MySQL - PDO 绑定参数
MySQL - PDO bindParam
$request_id_col
和 $request_id
是字符串。但是,table中的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 进行查询?
您不能绑定 table 或列名。只有值。
$request_id_col
和 $request_id
是字符串。但是,table中的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 进行查询?
您不能绑定 table 或列名。只有值。