I have script that retrieves information from database.
but here i dont understand
the call_user_array_func() and
referense operator why used here?
[code=php]<?php
function read()
{
$parameters = array();
$results = array();
$mysql = new mysqli(‘localhost’, ‘root’, ‘root’, ‘db’) or die(‘There was a problem connecting to the database’);
$stmt = $mysql->prepare(‘SELECT body FROM posts’) or die(‘Problem preparing query’);
$stmt->execute();
$meta = $stmt->result_metadata();
while ( $field = $meta->fetch_field() ) {
$parameters[] = &$row[$field->name];
}
call_user_func_array(array($stmt, ‘bind_result’), $parameters);
while ( $stmt->fetch() ) {
$x = array();
foreach( $row as $key => $val ) {
$x[$key] = $val;
}
$results[] = $x;
}
return $results;
}
$results = read();
?>
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”utf-8″>
<title>untitled</title>
</head>
<body>
<?php foreach ($results as $row) : ?>
<p> <?php echo $row[‘body’]; ?> </p>
<?php endforeach; ?>
</body>
</html>
i know this & reference operator but for what reason this is used i cannot understand. this section
[code=php] while ( $field = $meta->fetch_field() ) {
$parameters[] = &$row[$field->name];
}
and from where $row variable has come?
[code=php] while ( $stmt->fetch() ) {
$x = array();
foreach( $row as $key => $val ) {
$x[$key] = $val;
}
$results[] = $x;
}
if possible pls explain step by step what happens in this script
Thanks all for attention