ID: 50483 Comment by: pcdinh at gmail dot com Reported By: pcdinh at gmail dot com Status: Open Bug Type: MySQLi related Operating System: Windows XP PHP Version: 5.3.1 New Comment:
Could someone look at this issue please? Previous Comments: ------------------------------------------------------------------------ [2009-12-15 16:28:05] pcdinh at gmail dot com Description: ------------ mysqi_error() and mysqli_errno() does not capture last error message and error code if mysqli_real_query() executes on a stored procedure that returns multiple result sets but one of them is an error. As you can see from the below code, I have a SP that basically a set of SELECTs but the last one is invalid by intention. If executing the SP (e.x: CALL p2(2, 5) ) in a MySQL Query Manager, the following warning will show up: (1 row(s) returned) Execution Time : 00:00:00:000 Transfer Time : 00:00:00:000 Total Time : 00:00:00:000 (1 row(s) returned) Execution Time : 00:00:00:000 Transfer Time : 00:00:00:000 Total Time : 00:00:00:000 (1 row(s) returned) Execution Time : 00:00:00:000 Transfer Time : 00:00:00:000 Total Time : 00:00:00:000 Query : CALL p2(2, 5) Error Code : 1146 Table 'test.non_existent_' doesn't exist Execution Time : 00:00:00:000 Transfer Time : 00:00:00:000 Total Time : 00:00:00:000 However, mysqli does not work that way. It does not know what happens with the last query. It simply knows the last query does not return a result set. Reproduce code: --------------- <?php /* DELIMITER $$ CREATE PROCEDURE p2(X INT, Y INT) DETERMINISTIC BEGIN SELECT X ; SELECT X AS first_param, Y AS second_param; SELECT X, Y, X + Y AS sum_xy, X * Y AS prod_xy; SELECT 1 FROM non_existent_; -- Intentional error END$$ DELIMITER ; */ $conn = mysqli_connect("localhost", "root", "123456", "test"); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } $query = "CALL p2(2, 5)"; $success = mysqli_real_query($conn, $query); if (false === $success) { var_dump(mysqli_error($conn)); } $i = 0; do { $result = mysqli_store_result($conn); if (false !== $result) { echo ++$i."\n"; } else { var_dump(mysqli_error($conn)); } } while (mysqli_more_results($conn) && mysqli_next_result($conn)); /* close connection */ mysqli_close($conn); ?> Expected result: ---------------- 1 2 3 string(0) "Table 'test.non_existent_' doesn't exist" Actual result: -------------- 1 2 3 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=50483&edit=1