Skip to content

Commit f14ed7b

Browse files
committed
If mysqli_stmt_prepare fails then the error is populated in conn not in stmt
However, mysqli_stmt_prepare only checks for errors in statement. If exception mode is enabled the exception is not triggered because of this flawed logic. Fix: copy the error from conn to stmt. If mysqli_stmt_prepare is called from mysqli_prepare then it doesn't matter because we unset stmt immediately and check for errors in conn.
1 parent a3a0f37 commit f14ed7b

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

ext/mysqli/tests/mysqli_report.phpt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ require_once('skipifconnectfailure.inc');
5353
mysqli_autocommit($link, true);
5454
mysqli_commit($link);
5555
mysqli_rollback($link);
56+
$stmt = mysqli_stmt_init($link);
57+
mysqli_stmt_prepare($stmt, "SELECT id FROM test WHERE id > ?");
5658
while(mysqli_more_results($link)) {
5759
mysqli_next_result($link);
5860
$res = mysqli_store_result($link);
@@ -81,6 +83,8 @@ require_once('skipifconnectfailure.inc');
8183
mysqli_autocommit($link, true);
8284
mysqli_commit($link);
8385
mysqli_rollback($link);
86+
$stmt = mysqli_stmt_init($link);
87+
mysqli_stmt_prepare($stmt, "SELECT id FROM test WHERE id > ?");
8488
while(mysqli_more_results($link)) {
8589
mysqli_next_result($link);
8690
$res = mysqli_store_result($link);
@@ -324,6 +328,8 @@ Warning: mysqli_commit(): (%s/%d): Commands out of sync; you can't run this comm
324328

325329
Warning: mysqli_rollback(): (%s/%d): Commands out of sync; you can't run this command now in %s on line %d
326330

331+
Warning: mysqli_stmt_prepare(): (%s/%d): Commands out of sync; you can't run this command now in %s on line %d
332+
327333
Warning: mysqli_store_result(): (%s/%d): You have an error in your SQL syntax; check the manual that corresponds to your %s server version for the right syntax to use near 'FOO' at line 1 in %s on line %d
328334

329335
Warning: mysqli_stmt_attr_set(): (%s/%d): Not implemented in %s on line %d

ext/mysqlnd/mysqlnd_ps.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ MYSQLND_METHOD(mysqlnd_stmt, prepare)(MYSQLND_STMT * const s, const char * const
407407

408408
ret = conn->command->stmt_prepare(conn, query_string);
409409
if (FAIL == ret) {
410+
COPY_CLIENT_ERROR(stmt->error_info, *conn->error_info);
410411
goto fail;
411412
}
412413
}

0 commit comments

Comments
 (0)