PDO -> Execute
Posted: Sun Oct 24, 2010 9:08 pm
I've got a PHP PDO script that works fine with value in the query but doesn't work with question mark (?)
This one doesn't work.
Error - Warning: Invalid argument supplied for foreach() in <filename> on line <line number pointing on foreach...>
But this one works fine
What am I doing wrong?
This one doesn't work.
Error - Warning: Invalid argument supplied for foreach() in <filename> on line <line number pointing on foreach...>
Code: Select all
$sql = 'SELECT id,firstName,lastName FROM tableName WHERE id=?';
$pds = $pdo->prepare($sql);
$pds->execute(array($_SESSION['ftlogin']));
foreach ($pdo->query($sql) as $row) {
$name = $row['firstName'].' '.$row['lastName'];
}
Code: Select all
$sql = 'SELECT id,firstName,lastName FROM tableName WHERE id="'.$_SESSION['ftlogin'].'"';
$pds = $pdo->prepare($sql);
$pds->execute();
foreach ($pdo->query($sql) as $row) {
$name = $row['firstName'].' '.$row['lastName'];
}