I use MySQL PDO rather than MySQLi, but I've done some digging to show how I'd go about researching this. Here is the problematic method:
http://www.php.net/manual/en/mysqli-stmt.get-result.php
Several of the comments on that page refer to the same problem - MySQLi appears to want all columns to be bound to variables, which is a bit cumbersome if you are trying to write a generic routine. However one comment mentioned this:
http://php.net/manual/en/mysqli-stmt.bind-result.php
Aha! That reveals that you can now do the following, without having to bind output columns:
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_array(MYSQLI_NUM))
{
foreach ($row as $r)
{
print "$r ";
}
print "\n";
}
Give that a try?
From the comments, you discovered that get_result
is not always available on shared hosting, as it requires the non-standard PHP module mysqlnd
. In that case, you're either stuck with output column binding, or you can switch to PDO, which allows whole array rows/objects to be read.