42000 Syntax error in query when executing prepared statement
- by Griff McGriff
I have been pulling my hair out trying to swap my current script over to PDO. I have simplified the MySQL query for this example, but the error remains even with this version.
$sql = 'SELECT * FROM :table WHERE lastUpdate > :appDate';
try{
$db = connect();
$stmt = $db->prepare($sql);
$stmt->bindParam(':table', $table);
$stmt->bindParam(':appDate', $appDate);
foreach($tablesToCheck as $table){
$stmt->execute();
$resultset[] = $stmt->fetchAll();
}
} catch(PDOException $e){
print 'Error!: '.$e->getMessage().'<br/>';
}//End try catch
$stmt-errorInfo() returns:
( [0] => 42000 [1] => 1064 [2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the
right syntax to use near ''GroupName' WHERE lastUpdate > NULL' at line 1 )