The following error triggers a mysql error, this is due to query not binding the parameter to the statement. I do not understand why this is happening.
This is the error returned by the else clause:
ERROR -> 1064 : You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to
use near '? ORDER BY dateCreated DESC' at line 4`
Here is the code in question:
$userId = 1;
if ($stmt = $link->query("
SELECT o.id, dateCreated, firstValue
FROM user_orders o
LEFT JOIN order_delivery d ON o.id = d.id
WHERE o.userId = ?
ORDER BY dateCreated DESC
"))
{
$stmt->bind_param("i", $userId);
$stmt->execute();
$stmt->close();
}
else
{
$pageContent = '
<p>ERROR -> '.$link->errno.' : '.$link->error.'</p>
';
}
Could someone possibly point our where i have gone wrong with this and why this mysql error is occuring.
Thank you for taking the time to read through this!
Use
mysqli::prepare, notqueryto prepare your prepared statement.querywill try to run that query which isn’t valid until the parameters have been bound.