Mulla on tällainen php-koodi:
function echoReferences($db){
$getReferences = $db->prepare("SELECT * FROM references");
$getReferences->execute();
while($reference = $getReferences->fetchObject()){
/******/
}
}Tietokanta taulu on muotoa:
CREATE TABLE references( id int(11) NOT NULL AUTO_INCREMENT, productID int(11) NOT NULL, PRIMARY KEY (id), UNIQUE KEY id (id) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=5;
Kun php-koodin suorittaa, tulee seuraava virhe:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]:
Syntax error or access violation: 1064 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 'references' at line 1' in /**/functions.php:23
Stack trace:
#0 /**/functions.php(23): PDOStatement->execute()
#1 /**/index.php(7): echoReferences(Object(PDO))
#2 {main} thrown in /**/functions.php on line 23Ja kuten tuo väittää, on tuossa kyselyssä syntaksi virhe, mutta en sitä itse löydä, voisko joku auttaa?
"References" on mysql:n varattu sana.
Okei, no se selittää sitten tuonkin.
Aihe on jo aika vanha, joten et voi enää vastata siihen.