Cadre yu / AOP se erreur CDbCommand n'a pas réussi à exécuter l'instruction SQL: SQLSTATE [42000]
Question
Je suis en train d'insérer des données dans une table à l'aide du Cadre Yû avec l'objet PDO et obtenir l'erreur suivante
Je construis la requête en utilisant ce code
$connection = CActiveRecord::getDbConnection();
$sql="INSERT INTO sms_logs (to, from, message,error_code,date_send) VALUES (:to,:from,:message,:error_code,:date_send)";
$command=$connection->createCommand($sql);
$command->bindParam(":to",$to,PDO::PARAM_STR);
$command->bindParam(":from",$from,PDO::PARAM_STR);
$command->bindParam(":message",$message,PDO::PARAM_STR);
$command->bindParam(":error_code",$code,PDO::PARAM_STR);
$command->bindParam(":date_send",date("Y-m-d H:i:s"),PDO::PARAM_STR);
$command->execute();
Et puis, dès que je lance le code que je reçois
CDbCommand failed to execute the SQL statement: 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 'to, from, message,error_code,date_send) VALUES ('27724963345','27723663542','Hap' at line 1INSERT INTO sms_logs (to, from, message,error_code,date_send) VALUES (:to,:from,:message,:error_code,:date_send)
toutes les suggestions seront les bienvenues! en utilisant mySql comme db
La solution
Vous devez échapper le mot from
dans votre sql $. Il est un mot réservé .
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow