SQLSTATE [42000]:Yiiのフレームワーク/ PDOはCDbCommandは、SQL文の実行に失敗しましたエラーを取得します

StackOverflow https://stackoverflow.com/questions/2316616

  •  22-09-2019
  •  | 
  •  

質問

私は一緒にPDOオブジェクトとのYii Frameworkを使用して、テーブルにいくつかのデータを挿入し、次のエラーを取得しようとしている。

私はこのコードを使用してクエリを構築しています。

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

任意の提案は歓迎されます! DBとしてMySQLを使用して

役に立ちましたか?

解決

あなたは$ SQLでワードfromをエスケープする必要があります。それは予約語である。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top