通过PHP调用MySQL存储过程时出错

I'm trying to call a stored procedure from MySQL and get back the two OUT parameters (@eset and @leng). I would like to echo out these two parameters back to JavaScript where I have an XMLHttpRequest waiting for the results.

I'm getting this error :

Strict standards: mysqli::next_result(): There is no next result set. 

Here's my code:

<?php


//get the q parameter from URL
$q=$_GET["q"];
$eset= "";
$length= 0;

// Opens a connection to a MySQL server

$db= new mysqli('localhost', 'db_name', 'pass');
if (!$db) {  die('Not connected : ' . mysql_error());} 

// Set the active MySQL database

$db_selected = $db->select_db('db_name');
if (!$db_selected) {
  die ('Can\'t use db : ' . mysql_error());
} 

// Select all the rows in the markers table

$db->multi_query( "CALL  mst2($q, @eset, @leng);SELECT @eset as eset;SELECT @leng as length" );
$db->next_result();            // flush the null RS from the call
$eset=$db->store_result();       // get the RS containing the id
//echo $eset->fetch_object()->eset, "
";
$length= $db->store_result();
//echo $length->fetch_object()->leng, "
";
$response= $eset.$length;
//$eset->free();
//$length->free();


  //$response=str_shuffle($q);

//output the response
echo $response;
?>

I'm assuming the first argument of your stored procedure is VARCHAR, so the first problem is that you are passing the $q variable without quotes in the query. It should be like this:

$db->multi_query("CALL mst2('$q', @eset, @leng); SELECT @eset as eset; SELECT @leng as length");

Also, you don't need to make two SELECT calls, do it only once:

SELECT @eset AS eset, @leng AS leng;

Needless to say that user inputs should never be trusted. You should use prepared statements:

if (($stmt = $db->prepare("CALL mst2(?, @eset, @leng)"))) {
    $stmt->bind_param("s", $q);
    $stmt->execute();
    $stmt->close();

    if (($res = $db->query("SELECT @eset AS eset, @leng AS leng"))) {
        list($eset, $leng) = $res->fetch_array();
        $result = $eset.$length;
        echo $result;

        $res->free();
    }
}