From:             pcdinh at gmail dot com
Operating system: Windows XP
PHP version:      5.3.1
PHP Bug Type:     MySQLi related
Bug description:  mysqli_error() does not return error while using with 
mysqli_real_query()

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 bug report at http://bugs.php.net/?id=50483&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=50483&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=50483&r=trysnapshot53
Try a snapshot (PHP 6.0):            
http://bugs.php.net/fix.php?id=50483&r=trysnapshot60
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=50483&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=50483&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=50483&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=50483&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=50483&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=50483&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=50483&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=50483&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=50483&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=50483&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=50483&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=50483&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=50483&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=50483&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=50483&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=50483&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=50483&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=50483&r=mysqlcfg

Reply via email to