MySQL正确的语法在第1行错误附近使用'' [英] MySQL the right syntax to use near '' at line 1 error
问题描述
你好,我使用php运行查询,提示错误
hello i have a run a query using php it give error
您的SQL语法有误;检查与您的MySQL服务器版本相对应的手册,以找到在第1行的''附近使用正确的语法
但是当我回显查询并使用sqlyog软件手动运行时,它运行良好.谁能说这是什么问题 这是我生成的查询
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
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
)
这是我的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
)";
修改后
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());
推荐答案
问题是因为您使用"在多行上进行了查询,即PHP实际上将所有空格发送到MySQL中,这导致它错误.
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.
要么将其放在一行上,要么在每一行上附加:o)
Either put it on one line or append on each line :o)
Sqlyog必须在每行上修剪空白,以解释其工作原理.
Sqlyog must be trimming white spaces on each line which explains why its working.
示例:
$qr2="INSERT INTO wp_bp_activity
(
user_id,
(this stuff)component,
(is) `type`,
(a) `action`,
(problem) content,
primary_link,
item_id,....
这篇关于MySQL正确的语法在第1行错误附近使用''的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!