【问题标题】:Sphinx PDO multiple variables in execute errorSphinx PDO 执行错误中的多个变量
【发布时间】:2016-03-23 15:41:33
【问题描述】:

Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound 变量与令牌数不匹配

当我尝试使用多个变量执行以下 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 个变量吗?

【问题讨论】:

    标签: php mysql pdo 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();
    

    【讨论】:

    • 不同的错误 - 1064 sphinxql:语法错误,意外的 QUOTED_STRING,在 ''0' 和 '1000' 附近需要 CONST_INT(或 3 个其他标记)......
    猜你喜欢
    • 1970-01-01
    • 2018-12-11
    • 2011-07-18
    • 2012-12-29
    • 1970-01-01
    • 2012-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多