0

我正在尝试使用 Yii 框架和 PDO 对象将一些数据插入到表中,并得到以下错误

我正在使用此代码构建查询

$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();

然后,只要我运行代码,我就会得到

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)

欢迎任何建议!使用 mySql 作为数据库

4

1 回答 1

2

您需要转义from$sql 中的单词。它是一个保留字

于 2010-02-23T16:52:42.607 回答