duanbi9202 2012-01-10 16:12
浏览 46
已采纳

显然,当从PHP发送时,此查询中存在SQL语法错误,但它在PHPMyAdmin上运行正常

It's all in the title really.

I've got this SQL query, ugly I know, but it should at least work... It works when I use it in PHPMyAdmin but when sent from PHP I get a syntax error from MySQL. :(

INSERT INTO `shortname_revisions` (old_shortname , new_shortname) VALUES ('$old', '$new');

UPDATE `soft_data` SET shortname = REPLACE(shortname ,'$old', '$new');
UPDATE `shot_data` SET shortname = REPLACE(shortname ,'$old', '$new');
UPDATE `virus_scanning` SET shortname = REPLACE(shortname ,'$old', '$new');
UPDATE `lang_translations` SET shortname = REPLACE(shortname ,'$old', '$new');
UPDATE `ratings` SET shortname = REPLACE(shortname ,'$old', '$new');
UPDATE `file_data` SET shortname = REPLACE(shortname ,'$old', '$new');

The $new and $old variables when pasted into PHPMyAdmin to test, would contain any string. Use $old = "media-player"; $new = "video-player"; as examples.

Also, I'm not sure of the correct use of the back ticks and where they should be and when, maybe that's part the problem.

For everyone asking about the error, sorry, I didn't post it. And I sure ain't about to go and recreate the error to paste it here. It was a pretty generic "You have a syntax error in roughly this square quarter mile of code somewhere" error.

  • 写回答

2条回答 默认 最新

  • doufu6423 2012-01-10 16:20
    关注

    1) Each statement needs to be sent in a separate mysql_query() call.

    2) The backticks are fine but unecessary as there are no embedded blanks in any of those table names

    3) I don't know your data structure but UPDATE without a "where" clause could be considered to be slightly unusual (unless these are intentionally single-row tables)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改