2017-10-17 13 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(); $ select = $ connection-> select() - > from($ this-> getMainTable()); // rateQuery $ rateQuery */ $ rateQuery = $ this-> rateQueryFactory-> create(['request' => $ request]); $ rateQuery-> prepareSelect($ select);$ bindings = $ rateQuery-> getBindings(); $ result = $ connection-> fetchRow($ select、$ bindings); –

+0

私はgetBindingsにあなたは '$ bind'変数 – Rafael

関連する問題