PHP 8.5.0 Beta 1 available for testing

Voting

: five plus zero?
(Example: nine)

The Note You're Voting On

kaspy at example dot com
10 years ago
For those of you trying to bind rows into array,
<?php
$stmt
= $db->prepare('SELECT id, name, mail, phone, FROM contacts');
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($arr['id'], $arr['name'], $arr['mail'], $arr['phone']);
while (
$stmt->fetch()) {
$outArr[] = $arr;
}
$stmt->close();
return
$outArr;
?>
this will give you all the rows you asked for except that they would all be the same as the first one because of some gremlins in the background code (i've heard that PHP is trying to save memory here).

But this one works:
<?php
$stmt
= $db->prepare('SELECT id, name, mail, phone, FROM contacts');
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($a,$b,$c,$d);
while (
$stmt->fetch()) {
$outArr[] = ['id' => $a, 'name' => $b, 'mail' => $c, 'phone' => $d];
}
$stmt->close();
return
$outArr;
?>
Just don't use arrays to bind results :)

<< Back to user notes page

To Top