Sphinx PDO 多个变量在执行错误
Sphinx PDO multiple variables in execute error
Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound
variables does not match number of tokens
当我尝试使用多个变量执行以下 PDO 查询时出现上述错误。
$array = $sphinx->prepare("select * from `indexname` where MATCH ('@name (:search)') AND
`price` BETWEEN :min AND :max");
$array->execute(array(':search' => $search, ':min' => $min, ':max' => $max));
如果我只使用 :search
并将 :min and :max
更改为 $min and $max
,则查询有效。
$array = $sphinx->prepare("select * from `indexname` where MATCH ('@name (:search)') AND `price` BETWEEN $min AND $max");
$array->execute(array(':search' => $search));
我可以在使用 sphinx 执行时只使用 1 个变量吗?
使用占位符,您可以绑定 a complete data literal only。
因此您必须先在 PHP 中编译您的搜索模式,然后将其发送到查询:
$stmt = $sphinx->prepare("select * from `indexname` where MATCH (:search) AND
`price` BETWEEN :min AND :max");
$stmt->bindValue(':search', "@name ($search)");
$stmt->bindValue(':min', (int)$min, PDO::PARAM_INT);
$stmt->bindValue(':max', (int)$max, PDO::PARAM_INT);
$stmt->execute();
Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
当我尝试使用多个变量执行以下 PDO 查询时出现上述错误。
$array = $sphinx->prepare("select * from `indexname` where MATCH ('@name (:search)') AND
`price` BETWEEN :min AND :max");
$array->execute(array(':search' => $search, ':min' => $min, ':max' => $max));
如果我只使用 :search
并将 :min and :max
更改为 $min and $max
,则查询有效。
$array = $sphinx->prepare("select * from `indexname` where MATCH ('@name (:search)') AND `price` BETWEEN $min AND $max");
$array->execute(array(':search' => $search));
我可以在使用 sphinx 执行时只使用 1 个变量吗?
使用占位符,您可以绑定 a complete data literal only。
因此您必须先在 PHP 中编译您的搜索模式,然后将其发送到查询:
$stmt = $sphinx->prepare("select * from `indexname` where MATCH (:search) AND
`price` BETWEEN :min AND :max");
$stmt->bindValue(':search', "@name ($search)");
$stmt->bindValue(':min', (int)$min, PDO::PARAM_INT);
$stmt->bindValue(':max', (int)$max, PDO::PARAM_INT);
$stmt->execute();