I am having an issue with mysql conditional comment queries where errors are reported with no syntax error. It works in the case that at least one of the queries actually executes with a conditional.
I am using php 5.6.24 and mysql 5.5.52-cll
Example 1 (Success):
<?php
$conn = mysqli_connect("127.0.0.1", "aaatex_phppos", "phppos", "aaatex_phppos2");
$test1 = "
/*!40000 REPLACE INTO `phppos_app_config` (`key`, `value`) VALUES ('supports_full_text', '0') */;
/*!50604 REPLACE INTO `phppos_app_config` (`key`, `value`) VALUES ('supports_full_text', '1') */;";
mysqli_multi_query($conn,$test1);
print_r(mysqli_error_list($conn));
?>
supports_full_text value is 0 as expected.
Example 2 (Failure):
<?php
$conn = mysqli_connect("127.0.0.1", "aaatex_phppos", "phppos", "aaatex_phppos2");
$test2 = "
/*!50604 REPLACE INTO `phppos_app_config` (`key`, `value`) VALUES ('test', '0') */;
/*!50604 REPLACE INTO `phppos_app_config` (`key`, `value`) VALUES ('test', '1') */;";
mysqli_multi_query($conn,$test2);
print_r(mysqli_error_list($conn));
Errors received:
Array
(
[0] => Array
(
[errno] => 1064
[sqlstate] => 42000
[error] => 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 ';
/*!50604 REPLACE INTO `phppos_app_config` (`key`, `value`) VALUES ('test', '1' at line 1
)
)
Example 3 (Failure; but appears like success (see below message):
<?php
$conn = mysqli_connect("127.0.0.1", "aaatex_phppos", "phppos", "aaatex_phppos2");
$test3 = "
/*!40000 REPLACE INTO `phppos_app_config` (`key`, `value`) VALUES ('test', '0') */;
/*!50604 REPLACE INTO `phppos_app_config` (`key`, `value`) VALUES ('test', '0') */;
/*!50604 REPLACE INTO `phppos_app_config` (`key`, `value`) VALUES ('test', '1') */;";
mysqli_multi_query($conn,$test3);
print_r(mysqli_error_list($conn));
test value is 0 as expected.
Is this a bug in php or something I am doing wrong?
EDIT:
NOTE: I found that when the query fails it STOPS processing the rest of the file. So example 3 still has errors in the 2nd and 3rd queries; I just didn't catch all errors. The 40000 query works; but anything that does NOT run for current mysql version fails as a syntax error.