php MySQL 在第 1 行错误附近使用的正确语法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11155489/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MySQL the right syntax to use near '' at line 1 error
提问by Suneth Kalhara
hello i have a run a query using php it give error
你好,我有一个使用 php 的查询,它给出了错误
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 '' at line 1
您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以了解要在第 1 行的 '' 附近使用的正确语法
but when i echo the query and run manually using sqlyog software it runs fine. can anyone say whats the problem on here this is my generated query
但是当我回显查询并使用 sqlyog 软件手动运行时,它运行良好。谁能说这里有什么问题,这是我生成的查询
INSERT INTO wp_bp_activity
(
user_id,
component,
`type`,
`action`,
content,
primary_link,
item_id,
secondary_item_id,
date_recorded,
hide_sitewide,
mptt_left,
mptt_right
)
VALUES(
1,'activity','activity_update','<a title="admin" href="http://brandnewmusicreleases.com/social-network/members/admin/">admin</a> posted an update','<a title="242925_1" href="http://brandnewmusicreleases.com/social-network/wp-content/uploads/242925_1.jpg" class="buddyboss-pics-picture-link">242925_1</a>','http://brandnewmusicreleases.com/social-network/members/admin/',' ',' ','2012-06-22 12:39:07',0,0,0
)
and here is my php code
这是我的 php 代码
$qr2="INSERT INTO wp_bp_activity
(
user_id,
component,
`type`,
`action`,
content,
primary_link,
item_id,
secondary_item_id,
date_recorded,
hide_sitewide,
mptt_left,
mptt_right
)
VALUES(
$cid,'activity',
'activity_update',
'<a href=\"http://brandnewmusicreleases.com/social-network/members/$name/\" title=\"$name\">$name</a> posted an update',
'<a class=\"buddyboss-pics-picture-link\" href=\"http://brandnewmusicreleases.com/social-network/wp-content/uploads/$imgname\" title=\"$ionlyname\">$ionlyname</a>',
'http://brandnewmusicreleases.com/social-network/members/$name/',
' ',
' ',
'$time',
0,
0,
0
)";
after edited
编辑后
echo $qr2="INSERT INTO wp_bp_activity (user_id,component,`type`,`action`,content,primary_link,item_id,secondary_item_id,date_recorded,hide_sitewide,mptt_left,mptt_right) VALUES($cid,'activity','activity_update','<a href=\"http://brandnewmusicreleases.com/social-network/members/$name/\" title=\"$name\">$name</a> posted an update','<a class=\"buddyboss-pics-picture-link\" href=\"http://brandnewmusicreleases.com/social-network/wp-content/uploads/$imgname\" title=\"$ionlyname\">$ionlyname</a>','http://brandnewmusicreleases.com/social-network/members/$name/','','','$time',0,0,0)";
mysql_query($qr2) or die(mysql_error());
回答by Menztrual
the problem is because you have got the query over multiple lines using the " " that PHP is actually sending all the white spaces in to MySQL which is causing it to error out.
问题是因为您使用“”获得了多行查询,PHP 实际上将所有空格发送到 MySQL,这导致它出错。
Either put it on one line or append on each line :o)
要么把它放在一行上,要么在每一行上追加:o)
Sqlyog must be trimming white spaces on each line which explains why its working.
Sqlyog 必须在每一行上修剪空格,这解释了它为什么工作。
Example:
例子:
$qr2="INSERT INTO wp_bp_activity
(
user_id,
(this stuff)component,
(is) `type`,
(a) `action`,
(problem) content,
primary_link,
item_id,....
回答by vikash
INSERT INTO wp_bp_activity
(
user_id,
component,
`type`,
`action`,
content,
primary_link,
item_id,
secondary_item_id,
date_recorded,
hide_sitewide,
mptt_left,
mptt_right
)
VALUES(
1,'activity','activity_update','<a title="admin" href="http://brandnewmusicreleases.com/social-network/members/admin/">admin</a> posted an update','<a title="242925_1" href="http://brandnewmusicreleases.com/social-network/wp-content/uploads/242925_1.jpg" class="buddyboss-pics-picture-link">242925_1</a>','http://brandnewmusicreleases.com/social-network/members/admin/',' ',' ','2012-06-22 12:39:07',0,0,0
)

