|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2021-02-03 15:50 UTC] cmb@php.net
-Status: Open
+Status: Feedback
-Assigned To:
+Assigned To: cmb
[2021-02-03 15:50 UTC] cmb@php.net
[2021-02-14 04:22 UTC] php-bugs at lists dot php dot net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 18:00:01 2025 UTC |
Description: ------------ Calling sql query containing multiple statements with a CREATE TRIGGER statement inbetween results in an additional (flawed) ; to be added to the trigger code. The semicolon will only be added, if an additional statement follows after the CREATE TRIGGER statement (like 'SELECT * FROM Student;' in the example below). If the CREATE TRIGGER statement is the last, no semicolon is added (what is ok). The error happens with both, PDO (mysqlnd 5.0.12-dev - 20150407) and mysqli (mysqlnd 5.0.12-dev - 20150407) drivers. The error does not happen when the queries are executed from phpMyAdmin or from the mysql console (mysql -u root -h localhost test < triggerTest.sql). Tested with 10.1.16-MariaDB and 5.5.46-0 MySQL. If you wonder what the problem with the ; is about: it breaks mysqldump resulting in syntax errors. Test script: --------------- $sql = "DROP TRIGGER IF EXISTS TriggerStudent; DROP TABLE IF EXISTS Student; CREATE TABLE `test`.`Student`( `id` INT NOT NULL AUTO_INCREMENT, `idInc` INT NOT NULL, PRIMARY KEY (`id`) ) ENGINE = InnoDB; CREATE TRIGGER `TriggerStudent` BEFORE INSERT ON `Student` FOR EACH ROW SET NEW.`idInc` = NEW.id + 1; SELECT * FROM Student;"; $db = new PDO("mysql:host=localhost;dbname=test;charset=UTF8", "root", ""); $erg = $db->exec($sql); //$mysqli = new mysqli("localhost", "root", "", "test"); // Same problem //$mysqli->multi_query($sql); Expected result: ---------------- SET NEW.`idInc` = NEW.id + 1 in the Statement column of SHOW TRIGGERS. Actual result: -------------- SET NEW.`idInc` = NEW.id + 1; in the Statement column of SHOW TRIGGERS.