这个php foreach代码有什么问题?

$db = new PDO("mysql:host=$hostname;dbname=$database",$username,$password);

$menus = 'SELECT menus FROM menus';

foreach($db->query($menus) as $row ){
  echo "<li class=\"main\"> $row['mainLink'] $row['menus'] </a> </li>";
}

$row['mainLink'] is equal to <a href='yada yada.php'>.

$row['menus'] is equals to yada yada.

The code give me this error:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\xampp\htdocs\yada-yada\index.php on line 34

You can't do $row['mainlink'] inside a string "".

Try either " . $row['mainLink'] . " or {$row['mainLink']}

I guess following code should work

printf('<li class="main">%s %s</a></li>', $row['mainLink'], $row['menus']);