[英]PDO Exception “SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens”
[英]Exception SQL STATE [ HY093 ] : Invalid parameter number: number of bound variables does not match number of tokens
我收到错误:
SQLSTATE[HY093]:无效的参数编号:绑定变量的数量与标记数量不匹配。
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;
}
消息:SQLSTATE[HY093]:无效参数数:绑定变量数与令牌数不匹配,查询为:SELECT
shipping_rbx
.* FROMshipping_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 BYdest_country_id
DESC,dest_region_id
DESC,dest_province
DESC,dest_city
DESC,condition_value
DESC LIMIT 1/ in /venoagent/framework Webapi/ErrorProcessor.php:195堆栈跟踪:#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
我没有看到您在代码中绑定了这些参数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.