异常 SQL STATE [HY093]:参数编号无效:绑定变量的数量与标记的数量不匹配

Exception SQL STATE [ HY093 ] : Invalid parameter number: number of bound variables does not match number of tokens

我遇到错误:

SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens.

public function prepareSelect(\Magento\Framework\DB\Select $select)
{
    $select->where(
        'website_id = :website_id'
    )->order(
        ['dest_country_id DESC', 'dest_region_id DESC', 'dest_province DESC', 'dest_city DESC', 'condition_value DESC']
    )->limit(
        1
    );

    // Render destination condition
    $orWhere = '(' . implode(
        ') OR (',
        [
            "dest_country_id = :country_id AND dest_region_id = :region_id AND dest_province = :dest_province AND dest_city = :dest_city"
        ]
    ) . ')';
    $select->where($orWhere);

    // Render condition by condition name
    if (is_array($this->request->getConditionName())) {
        $orWhere = [];
        foreach (range(0, count($this->request->getConditionName())) as $conditionNumber) {
            $bindNameKey = sprintf(':condition_name_%d', $conditionNumber);
            $bindValueKey = sprintf(':condition_value_%d', $conditionNumber);
            $orWhere[] = "(condition_name = {$bindNameKey} AND condition_value <= {$bindValueKey})";
        }

        if ($orWhere) {
            $select->where(implode(' OR ', $orWhere));
        }
    } else {
        $select->where('condition_name = :condition_name');
        $select->where('condition_value <= :condition_value');
    }
    return $select;
}

/**
 * @return array
 */
public function getBindings()
{
    $bind = [
        ':website_id' => (int)$this->request->getWebsiteId(),
        ':country_id' => $this->request->getDestCountryId(),
        ':region_id' => (int)$this->request->getDestRegionId(),
        ':province' => $this->request->getProvince(),
        ':city' => $this->request->getCity(),
        ':postcode' => $this->request->getDestPostcode(),
    ];

    // Render condition by condition name
    if (is_array($this->request->getConditionName())) {
        $i = 0;
        foreach ($this->request->getConditionName() as $conditionName) {
            $bindNameKey = sprintf(':condition_name_%d', $i);
            $bindValueKey = sprintf(':condition_value_%d', $i);
            $bind[$bindNameKey] = $conditionName;
            $bind[$bindValueKey] = $this->request->getData($conditionName);
            $i++;
        }
    } else {
        $bind[':condition_name'] = $this->request->getConditionName();
        $bind[':condition_value'] = $this->request->getData($this->request->getConditionName());
    }

    return $bind;
}

Message: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens, query was: SELECT shipping_rbx.* FROM shipping_rbx WHERE (website_id = :website_id AND dest_country_id = :country_id AND dest_region_id = :region_id AND dest_province = :dest_province AND dest_city = :dest_city) AND (condition_name = :condition_name) AND (condition_value <= :condition_value) ORDER BY dest_country_id DESC, dest_region_id DESC, dest_province DESC, dest_city DESC, condition_value DESC LIMIT 1' in /vendor/magento/framework/Webapi/ErrorProcessor.php:195

Stack trace:#0 /vendor/magento/framework/Webapi/ErrorProcessor.php(139): Magento\Framework\Webapi\ErrorProcessor->_critical(Object(Zend_Db_Statement_Exception))#1 /vendor/magento/module-webapi/Controller/Rest.php(219): Magento\Framework\Webapi\ErrorProcessor->maskException(Object(Zend_Db_Statement_Exception))#2 /var/generation/Magento/Webapi/Controller/Rest/Interceptor.php(24): Magento\Webapi\Controller\Rest->dispatch(Object(Magento\Framework\App\Request\Http))#3 /vendor/magento/framework/App/Http.php(135): Magento\Webapi\Controller\Rest\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))#4 /vendor/magento/framework/App/Bootstrap.php(258): Magento\Framework\App\Http->launch()#5 /index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))#6 {main}[][]

在 phpmadmin 中执行查询时,它工作正常并显示一行。

我认为你有以下问题:

:dest_province :dest_city

我没有看到您在代码中绑定了这些参数