|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54221 mysqli::get_warnings segfault when used in multi queries
Submitted: 2011-03-11 09:39 UTC Modified: 2011-03-17 11:32 UTC
From: glen at delfi dot ee Assigned: mysql
Status: Closed Package: MySQLi related
PHP Version: 5.3.5 OS:
Private report: No CVE-ID:
 [2011-03-11 09:39 UTC] glen at delfi dot ee

can't use mysqli::get_warnings with multi queries reliably as it will get either 
segfault or empty result.

the code is supposed to print 2 times warning:
"Warning: 1050: Table 'a' already exists"
"Warning: 1050: Table 'a' already exists"

but instead it segfaults (PHP 5.3.5).

also if i run queries where only one warning is printed. it will not segfault. 
segfault seems to happen in ->next() call.

seems is because internally this is implemented as "SHOW WARNINGS" query [1]


segfault must be fixed, but regarding the usage, perhaps document that you can't 
use it sanely with multi queries, due limitations of mysql protocol, as seems it 
is problem in mysql protocol, that it returns warnings only from last of the 
multi query

Test script:
$dbh = new mysqli(null, null, null, "test");
if ($dbh->connect_error) {
        die('Connect Error (' . $dbh->connect_errno . ') ' . $dbh->connect_error);

$create = "create temporary table if not exists a (a int4)";
$query = "$create;$create";$create;";
if ($dbh->multi_query($query)) {
        do {
                $sth = $dbh->store_result();

                if ($dbh->warning_count) {
                        $e = $dbh->get_warnings();
                        do {
                                echo "Warning: $e->errno: $e->message\n"; 
                        } while ($e->next()); 
        } while ($dbh->next_result());


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-03-17 11:06 UTC]
-Status: Open +Status: Assigned -Assigned To: +Assigned To: mysql
 [2011-03-17 11:06 UTC]
 [2011-03-17 11:28 UTC]
Automatic comment from SVN on behalf of andrey
Log: Fix for bug #54221 mysqli::get_warnings segfault when used in multi queries
 [2011-03-17 11:32 UTC]
-Status: Assigned +Status: Closed
 [2011-03-17 11:32 UTC]
Fixed. The fix will be part of 5.3.7.
PHP Copyright © 2001-2015 The PHP Group
All rights reserved.
Last updated: Sat Oct 10 05:01:32 2015 UTC