|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46448 mysqli_multi_query() with invalid queries closes MySQL connection
Submitted: 2008-11-01 09:41 UTC Modified: 2008-11-27 14:13 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: pcdinh at gmail dot com Assigned: mysql (profile)
Status: Not a bug Package: MySQLi related
PHP Version: 5.2.7RC2 OS: *
Private report: No CVE-ID: None
 [2008-11-01 09:41 UTC] pcdinh at gmail dot com
Make a multiple queries that contains a buggy DML SQL command with mysqli_multi_query can cause MySQL connection closed: mysqli_ping returns false right after mysqli_multi_query() invocation.

Apache 2.2.6
MySQL 5.0.67

Reproduce code:
ini_set('mysqli.reconnect', 'Off');
$mysqli = mysqli_init();
mysqli_real_connect($mysqli, "localhost", "root", "123456", "test");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());


CREATE TABLE `test2` (
  `id` int(11) DEFAULT NULL,
  `username` varchar(100) DEFAULT NULL

Buggy DML SQL command: INSERT INTO test2 VALUES (1008-, 'pcdinh5')

$query = "INSERT INTO test2 VALUES (1007, 'pcdinh4');INSERT INTO test2 VALUES (1008-, 'pcdinh5');";

/* execute multi query */
mysqli_multi_query($mysqli, $query);

if (false === mysqli_ping($mysqli))
    exit('Database connection is closed');


Expected result:
Nothing happens. If this script produces a message: Database connection is closed means there is a problem

Actual result:
This script produces a message: Database connection is closed


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-11-27 14:13 UTC]
mysql_multi_query returns multiple resultsets (error/ok packets), so you can't execute another command.

Please check examples for mysqli_multi_query and use proper error handling in your script. mysqli_ping should fail with error message "commands out of sync".
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Thu Dec 07 04:01:28 2023 UTC