我在php中使用原始(不變)ezsql-mysql類。我的數據庫引擎是innodb。一切都很好,但在一個頁面中只有一個查詢。當我從一些其他工作頁面複製代碼庫時,所有需要的類和功能都已添加。就在問題查詢之前還有另一個正常工作的查詢。當我直接將它複製粘貼到phpmyadmin時,帶有問題的查詢也在php文件之外工作。Mysql查詢不能在Php文件中工作
$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;
";
每當我使用該頁時,我的服務器會在該頁的目錄中生成錯誤日誌。且誤差
[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
,這就是發生在我只是複製和在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).
能否請你幫我找到了什麼問題?在最糟糕的情況下,我可以更改我的代碼以使其以不同的方式工作。但是,我正在尋求幫助來理解。因爲它看起來很奇怪,以至於在phpmyadmin上正常工作的查詢在php文件中有問題。
在此先感謝。
不要將'begin'和'commit'作爲同一查詢的一部分......如果您使用的是事務性數據庫引擎,請將它們作爲單獨查詢 –