我有一个涉及BETWEEN
语句的查询,无法查看如何为其绑定参数:
try {
include("../epsadmin/connectpdo.php");
$sql="SELECT * FROM properties
WHERE location LIKE :location
AND bedrooms LIKE :bedrooms
AND category LIKE :category
AND price BETWEEN :minPrice and :maxPrice
ORDER BY postcode";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':location', $_REQUEST['location'], PDO::STR);
$stmt->bindParam(':bedrooms', $_REQUEST['bedrooms'], PDO::STR);
$stmt->bindParam(':category', $_REQUEST['category'], PDO::STR);
//bindParam for price BETWEEN minPrice and MaxPrice needed
$stmt->execute();
$total = $stmt->rowCount();
$obj = $stmt->fetchObject();
}//end try
catch(PDOException $error) {
$send='DB Query failed: ' . $error->getMessage();
header("Content-type: text/plain");
echo $send;
exit;
}
有人可以帮助处理所需的bindParam
声明吗?
答案 0 :(得分:0)
如何为涉及BETWEEN语句的查询执行预准备语句
与任何其他查询完全相同:向查询添加必要的占位符,然后使用bindParam
方法绑定它们。