Php mysql语句中的错误
我找不到我的错误在哪里Php mysql语句中的错误,php,mysql,Php,Mysql,我找不到我的错误在哪里 $result= mysql_query(" INSERT INTO inbox ( messages, from, to, date, control_panel_id, title ) VALUES( '".$message."' , '".$this->sender."' , '".$this->recipient."', NOW() , '".$this->co
$result= mysql_query(" INSERT INTO inbox ( messages, from, to, date, control_panel_id, title )
VALUES( '".$message."' , '".$this->sender."' , '".$this->recipient."', NOW() , '".$this->control_panel_id."' , '".$title."' )
") or die(mysql_error());
我得到:
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 'from, to, date, control_panel_id, title ) VALUES( ' ' at line 1
我在做什么,这是错误的?当使用它们作为名称或别名时,您需要引用中的。可以通过使用反勾号围绕它们来实现这一点,例如:
SELECT messages, `from`, ...
如果有疑问,可以安全地引用所有列名
INSERT INTO `inbox`
(`messages`, `from`, `to`, `date`, `control_panel_id`, `title`)
VALUES
-- etc...
也可以考虑避免将来保留的WORSD的名称,以避免类似的问题。
当使用它们作为名称或别名时,你需要引用< <代码> > <代码> >。可以通过使用反勾号围绕它们来实现这一点,例如:
SELECT messages, `from`, ...
如果有疑问,可以安全地引用所有列名
INSERT INTO `inbox`
(`messages`, `from`, `to`, `date`, `control_panel_id`, `title`)
VALUES
-- etc...
此外,您还可以考虑避免将来保留的WORSD的名称,以避免类似的问题。
<代码> < <代码> >是SQL中的保留字。如果这是一个列名,则必须始终将其括在反勾中。(或ANSI模式的双引号)
您还可以通过实际使用双引号编写mysql_查询字符串,从而减少麻烦:
$result = mysql_query("
INSERT INTO inbox
( messages, `from`, `to`, `date`,
control_panel_id, title )
VALUES
( '$message', '$this->sender', '$this->recipient',
NOW() , '$this->control_panel_id', '$title' )
")
or die(mysql_error());
(而PHP数据库接口就更省力了,等等)from
在SQL中是一个保留字。如果这是一个列名,则必须始终将其括在反勾中。(或ANSI模式的双引号)
您还可以通过实际使用双引号编写mysql_查询字符串,从而减少麻烦:
$result = mysql_query("
INSERT INTO inbox
( messages, `from`, `to`, `date`,
control_panel_id, title )
VALUES
( '$message', '$this->sender', '$this->recipient',
NOW() , '$this->control_panel_id', '$title' )
")
or die(mysql_error());
(PHP数据库接口甚至更省力,bla bla..)Mysql不支持某些关键字,因为它在Mysql语法中使用,所以我认为您需要更改
关键字from、to和date to other name…Mysql不支持某些关键字,因为它在Mysql语法中使用,所以我认为您需要更改
关键词from、to和date to other name…from
是保留字。如何使用它?
中的是一个保留字。你如何使用它呢?这里有一个完整的保留字列表@Jona:谢谢。添加了我帖子的链接。可以在这里找到保留字的完整列表@Jona:谢谢。在我的帖子中添加了链接。感谢backticks和co“”之间的区别。一对单引号backticks用于标识符(列名和表名),而单引号仅在SQL中包含字符串值。感谢backticks和co“”之间的区别。一对单引号backticks用于标识符(列名称和表名称),而单引号仅在SQL中包含字符串值。