你好,我有一个使用php运行查询它给出错误
您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,以便在第1行附近使用正确的语法
但是当我回显查询并使用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
)
这是我的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());
答案 0 :(得分:18)
问题是因为您使用“”实际上将所有空白空间发送到MySQL而导致错误输出的多行查询。
将其放在一行或附加在每一行:o)
Sqlyog必须在每条线上修剪空白区域,这就解释了它的工作原理。
示例:
$qr2="INSERT INTO wp_bp_activity
(
user_id,
(this stuff)component,
(is) `type`,
(a) `action`,
(problem) content,
primary_link,
item_id,....
答案 1 :(得分:-2)
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
)