插入序列化对象时出现MySQL错误1064

时间:2013-03-04 00:47:25

标签: php mysql

所以我有一个自定义的PHP对象,我已经序列化了,我试图用PHP将它插入MySQL数据库 代码:

$serializedOrder = serialize($objectOrder);

//I have tried both of these, and all combinations of them
$serializedOrder = mysql_real_escape_string($serializedOrder);
$serializedOrder = stripslashes($serializedOrder);

$result = mysql_query("INSERT INTO orders(order) VALUES('".$serializedOrder."')");
if ($result == false) {
   echo "mysql_query failed  ";
   echo mysql_error();
   echo "   ";
   echo mysql_errno();
}

这产生了反应:

mysql_query失败您的SQL语法出错了;检查与MySQL服务器版本对应的手册,以便在'order'附近使用正确的语法VALUES('O:10:“OrderClass”:6:{s:9:“foodArray”; a:0:{} s: 8:“baseTime”; i:0; s:1'在第1行1064

总序列化字符串是:

0:10: “OrderClass”:6:{S:9: “foodArray”;一个:0:{} S:8: “baseTime”; I:0; S:11: “ORDERNUMBER”; I: 0; S:11: “truckNumber”; I:0; S:10: “的customerID”; I:0; S:11: “orderStatus”; S:0: “”;}

感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

正确的查询

$result = mysql_query("INSERT INTO orders(`order`) VALUES('".$serializedOrder."')");

https://dev.mysql.com/doc/refman/4.1/en/reserved-words.html