ID:               50462
 Comment by:       pcdinh at gmail dot com
 Reported By:      pcdinh at gmail dot com
 Status:           Open
 Bug Type:         MySQLi related
 Operating System: Windows XP
 PHP Version:      5.3.1
 New Comment:

Hi,

I found that mysqli_more_results() return true when there is more than

1 query

<?php
$link = mysqli_connect("localhost", "root", "123456", "test");

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

$query  = "SELECT 1;";
$query  .= "SELECT 1;"; // second query

/* execute multi query */
if (mysqli_multi_query($link, $query)) {
    var_dump(mysqli_more_results($link)); 
}

?>

bool(true)

However, this behavior is totally confused


Previous Comments:
------------------------------------------------------------------------

[2009-12-12 21:41:44] pcdinh at gmail dot com

Description:
------------
mysqli_more_results() will always return false after 
mysqli_multi_query() for both SELECT and non SELECT queries

Therefore I can not use the loop while (mysqli_more_results()) in 
combination with mysqli_next_result() to iterate through result sets 
produced by SELECT queries

mysqli_multi_query($conn, $query);

while (mysqli_more_results($conn))
{
    mysqli_next_result($query);

    /* store first result set */
    if ($result = mysqli_store_result($conn)) {
 
    }
}

Code example in http://php.net/manual/en/mysqli.multi-query.php is 
outdated because it causes E_STRICT in PHP 5.3.1. It requires 
mysqli_more_results() to be called before mysqli_next_result()

There is a workaround

if (mysqli_multi_query($link, $query)) {
    do {
        /* store first result set */
        if ($result = mysqli_store_result($link)) {
            while ($row = mysqli_fetch_row($result)) {
                printf("%s\n", $row[0]);
            }
            mysqli_free_result($result);
        }

        // print divider => will never work
        if (mysqli_more_results($link)) {
            printf("-----------------\n");
        }
    } while (mysqli_more_results($link) && mysqli_next_result($link));
}

but mysqli_more_results() seems to do nothing related to result sets 
here


Reproduce code:
---------------
<?php
$link = mysqli_connect("localhost", "root", "123456", "test");

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

$query  = "SELECT 1";

/* execute multi query */
if (mysqli_multi_query($link, $query)) {
    var_dump(mysqli_more_results($link));      
}

/* close connection */
mysqli_close($link);
?>

Expected result:
----------------
bool(true)

Actual result:
--------------
bool(false)


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=50462&edit=1

Reply via email to