$request_id_col
和 $request_id
是字符串。但表中的request_id_col类型是整数。
$stmt = $db->prepare(' SELECT r.qty, d.name
FROM requested_devices r
JOIN devices d ON r.device_id = d.id
WHERE r.:request_id_col = :request_id
ORDER BY r.id');
$stmt->bindParam(':request_id_col', $request_id_col);
$stmt->bindParam(':request_id', $request_id);
$stmt->execute();
我收到错误
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 ''sample_id' = '101' ORDER BY r.id' at line 4'
如何正确使用bindParam进行查询?
最佳答案
您无法绑定(bind)表名或列名。只有值。
关于MySQL-PDO 绑定(bind)参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28124725/