phpmysqliprepared-statementmultiple-resultsets

Call to undefined method mysqli_stmt::next_result()


I'm trying to loop through a stored procedure, called via prepared statement, in PHP. Hopefully it's not impossible. Here's my PHP code:

$database = new mysqli($server, $user, $pass, $db);
$stmt = $database->prepare("CALL thisShouldReturnEightResultSets (?)");
$stmt->bind_param("i", $id);
$stmt->execute();

do {
    if ($res = $stmt->bind_result($myvar)) {
        $stmt->fetch();
        echo "*" . $myvar . "<br/>";
    } else {
        if ($stmt->errno) {
            echo "Store failed: (" . $stmt->errno . ") " . $stmt->error;
        }
    }
} while ($stmt->next_result());

That should print like so:

* 4
* 16
* 7
etc...

... and then exit once it runs of out result sets. Instead I get:

* 4

Fatal error: Call to undefined method mysqli_stmt::next_result()

At first I tried get_result instead of bind_result, but that errored. Based on this I found that I don't have the mysqlnd driver installed. Iworked around that with bind_result. Now I need a work around for next_result which I'm guessing is part of the mysqlnd driver as well. What are my options here? Tech notes:

PHP Version 5.3.2-1ubuntu4.11

Thanks.


Solution

  • I don't think you can do this with a prepared statement, since you don't have the MYSQLND driver. You'll have to do it the old fashioned way, with escaping.

    $id = $database->real_escape_string($id);
    if ($database->multi_query("CALL thisShouldReturnEightResultSets ('$id')")) {
        do {
            if ($result = $database->store_result()) {
                while ($row = $result->fetch_row()) {
                    echo "*" . $row[0] . "<br/>";
                }
            }
        } while ($database->next_result());
    }