문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top