42000 Syntax error in query when executing prepared statement

Posted by Griff McGriff on Stack Overflow See other posts from Stack Overflow or by Griff McGriff
Published on 2012-11-27T21:33:27Z Indexed on 2012/12/04 23:04 UTC
Read the original article Hit count: 189

Filed under:
|
|
|

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 )

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql