php.net |  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
Votes:1
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: pcdinh at gmail dot com
New email:
PHP Version: OS:

 

 [2008-11-01 09:41 UTC] pcdinh at gmail dot com
Description:
------------
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:
---------------
<?php
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());
    exit();
}

/*

CREATE TABLE `test2` (
  `id` int(11) DEFAULT NULL,
  `username` varchar(100) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-11-27 14:13 UTC] georg@php.net
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-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 18:01:29 2024 UTC