开发者

Yii Framework/PDO getting error CDbCommand failed to execute the SQL statement: SQLSTATE[42000]

开发者 https://www.devze.com 2022-12-21 11:44 出处:网络
I\'m trying to insert some data into a table using the Yii Framework together with the PDO object and get the following error

I'm trying to insert some data into a table using the Yii Framework together with the PDO object and get the following error

开发者_开发技巧I'm building the query using this 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();

And then as soon as I run the code I get

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)

any suggestions will be welcome! using mySql as the db


You need to escape the word from in your $sql. It is a reserved word.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号