2017-10-17 1131 views
-1

我得到了错误的号码:异常SQL STATE [HY093]:无效的参数编号:绑定变量的数量不符令牌

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查询,它工作正常,并显示一排。

回答

0

我认为你有问题:

:dest_province :dest_city

我没有看到你在你的代码

+0

,我需要两个绑定绑定这些这些PARAMS?这是自定义模块相同的几率运输方式。 –

+0

这样我在资源模型里面使用了这个函数: $ connection = $ this-> getConnection(); ($ this-> getMainTable()); $ select = $ connection-> select() - > from($ this-> getMainTable()); /** @var RateQuery $ rateQuery */ $ rateQuery = $ this-> rateQueryFactory-> create(['request'=> $ request]); $ rateQuery-> prepareSelect($ select); $ bindings = $ rateQuery-> getBindings(); $ result = $ connection-> fetchRow($ select,$ bindings); –

+0

我想在getBindings你应该这样做 在'$ bind'变量 – Rafael

相关问题