dongshi3361 2013-09-29 18:55
浏览 60
已采纳

Mysql查询无法在Php文件中工作

I am using original(no-change) ezsql-mysql class in php. my database engine is innodb. everything works great but one query in one page. As I copy the code base from some other working pages everything needed like the classes and functions are already added. Just before the problem query there is another query which is working normally. Also the query with problem is working outside of php file when I directly copy paste it to the phpmyadmin.

    $db->query("
    BEGIN;
    INSERT INTO places (name, latitude, longitude) 
      VALUES ('Place of $event_name', '$latitude', '$longitude');
    INSERT INTO events (place_code, event_name, start_time, owner_id) 
      VALUES (LAST_INSERT_ID(),'$event_name', '$start_time', '$owner_id');
    COMMIT;
    ");
//this echo part was just for copying to phpmyadmin
    echo "
    BEGIN;
    INSERT INTO places (name, latitude, longitude) 
      VALUES('Place of $event_name', '$latitude', '$longitude');
    INSERT INTO events (place_code, event_name, start_time, owner_id) 
      VALUES(LAST_INSERT_ID(),'$event_name', '$start_time', '$owner_id');
    COMMIT;
    ";

Everytime I use that page my server generates an error log in the directory of that page. and the error is

    [29-Sep-2013 12:58:00] PHP Warning:  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 'INSERT INTO places (name, latitude, longitude) 
  VALUES ('Place of asd', '39.76' at line 2 in /home7/eyselnet/public_html/business/injoin/demo/sql/ez_sql_mysql.php on line 233

And this is what happen When I just copy and paste same query in phpmyadmin

BEGIN;# MySQL returned an empty result set (i.e. zero rows).
 INSERT INTO places (name, latitude, longitude) VALUES('Place of asd', '39.7617657', '30.5056083');# 1 row affected.
 INSERT INTO events (place_code, event_name, start_time, owner_id) VALUES(LAST_INSERT_ID(),'asd', '1357884000', '1');# 1 row affected.
 COMMIT;# MySQL returned an empty result set (i.e. zero rows).

Can you please help me find out what is the problem? In the worst case I can change my code to make it work in a different way. But instead of that I am asking for help to understand. because it look so strange that a query which work normally on phpmyadmin is having problem in the php file.

thanks in advance.

  • 写回答

1条回答 默认 最新

  • douzongmu2543 2013-09-29 18:58
    关注

    I don't know about the mentioned class, but mysql(i) functions in php (I guess PDO, too) only let you perform one query per function call. So you will need to separate your BEGIN; and COMMIT; to own MySQL queries.

    EDIT: You will of course have to do the two INSERTs separately, too.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?