I have a PHP loop.
Inside a loop I will have a Select statement.
I get error
Fatal error: Uncaught Error: Cannot pass parameter 2 by reference
I don't know what I am doing wrong.
This is my statement
<?php
$query = "SELECT customer.id AS customerid,customer.doc,
order.id AS orderid ,order.doc FROM customer
Inner Join order ON customer.doc = order.doc
Where customer.doc= ?";
if ($stmt = $mysqli->prepare($query)) {
$stmt->bind_param("i", 'DOC48599');
/* execute query */
$stmt->execute();
/* store result */
$stmt->store_result();
printf("Number of rows: %d.
", $stmt->num_rows);
/* close statement */
$stmt->close();
}
/* close connection */
$mysqli->close();
?>
And my second question is what is the best practice to have Select statement inside Loop.
So for each loop, it's going through; it will get an ID and do select statement binding the ID in the select statement.
Thanks
The error is in this line:
$stmt->bind_param("i", 'DOC48599');
You cannot pass values directly the string 'DOC48599' as a parameter, you need to store it in a variable and then pass the variable to the bind_param
method.
You also have to pay attention to the type of the parameter passed: if your parameter is a string, you need to use "s" instead of "i". Take a look here
$myParameter = 'DOC48599';
$stmt->bind_param("s", $myParameter);