0

I'm trying to get the values of a column dateTime and then using those values get the number of entries made on that day. So I'm passing an array to bind_param. But here I get the error:

"Parameter 3 to mysqli_stmt_bind_param() expected to be a reference"

I've also tried the commented method which doesn't seem to work either. Here's the code :

<?php
$hostname = "localhost";
$database = "ti_project";
$username = "root";
$password = "";
$mysqli = new mysqli($hostname, $username, $password, $database);

$query = "SELECT dateTime FROM feedback";
$result = $mysqli->prepare($query);
/*$result->bind_param('s', $datetime);*/
$result->execute();

$result->bind_result($Date);

while ($result->fetch()){
 $feedbackdate[] = array($Date);
}

$type="s";
$query = "SELECT COUNT(*) FROM feedback WHERE dateTime = ?";
$result = $mysqli->prepare($query);
call_user_func_array('mysqli_stmt_bind_param', 
                array_merge (array($result, $type),$feedbackdate));

$result->execute();


/*$ref    = new ReflectionClass('mysqli_stmt'); 
$method = $ref->getMethod("bind_param"); 
$method->invokeArgs($result,$feedbackdate); 
$result->execute(); 
*$result->bind_*result($count);*/

while ($result->fetch()){
    $Count[] = array(
    'Count' => $count
);
}
echo json_encode($Count);

$result->close();

$mysqli->close();

?>
halfer
  • 19,824
  • 17
  • 99
  • 186
Saeesh
  • 15
  • 3
  • 1
    Possible duplicate of [mysqli bind\_param() expected to be a reference, value given](http://stackoverflow.com/questions/16120822/mysqli-bind-param-expected-to-be-a-reference-value-given) – Rajdeep Paul Jan 21 '16 at 07:25

1 Answers1

0

Missing the statement variable in your function call. This function accepts 3 parameters and not 2. You are missing to provide the prepared statement.

call_user_func_array('mysqli_stmt_bind_param', $stmt, array_merge (array($result, $type), $feedbackdate));

Please read the mysqli_stmt_bind_param function reference here

Rahul Kate
  • 700
  • 1
  • 5
  • 10