Nikk
Nikk

Reputation: 7921

MySQLi multi_query wont return more than 1 results

When the result is limited to 1, everything works great.

However, when I have more than 1 results...it doesn't return anything.

$output = $conn->multi_query("CALL `test_discount`('022979', 1101, 1, 'W', 100, @out); SELECT @out AS `discount`;");

if ($output == true){
    while($conn->next_result()){
        $result = $conn->store_result();
            while ($row = $result->fetch_assoc()){
                print_r($row);
                break;
            }                   
    if($conn->more_results() == false) { break; };
    }
}

Am guessing I am doing something wrong?

Upvotes: 1

Views: 545

Answers (1)

Your Common Sense
Your Common Sense

Reputation: 158005

If SQL above makes any sense, then I would suggest to fetch the data returned by the procedure first, and then select that stray @out variable.

$sql = "CALL `test_discount`('022979', 1101, 1, 'W', 100, @out)";
$res = $conn->multi_query($sql);
do {
    if ($res = $mysqli->store_result()) {
        foreach ($res as $row) {
            print_r($row);
        }
    }
} while ($mysqli->more_results() && $mysqli->next_result());

$out = $conn->query("SELECT @out")->fetch_row[0];

Upvotes: 1

Related Questions