[英]MySQL BETWEEN with PDO prepared statements
I have a query involving a BETWEEN
statement and cannot see how to bind the parameters for it: 我有一个涉及
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;
}
Could anybody help with the required bindParam
statement? 任何人都可以帮助所需的
bindParam
语句吗?
how to do the prepared statement for a query involving a BETWEEN statement
如何为涉及BETWEEN语句的查询做准备的语句
Exactly the same way as with any other query: By adding the necessary placeholders to the query and then by binding them using the bindParam
method. 与任何其他查询完全相同:将必要的占位符添加到查询中,然后使用
bindParam
方法绑定它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.