2012-04-21 9 views
0

zend fraworkでクエリを実行する必要があります。クエリは以下のとおりです。zend FrameworkのFetchList()が機能しない

select * from users where role_id in (3,5) and emailID not in ('[email protected]', '[email protected]'); 

私は

$this->fetchList($whereString) // where $this is object of users 

に文字列に

$whereString = role_id in (3,5) and emailID not in ('[email protected]', '[email protected]'); 

を渡しています。しかしfetchList()関数はemailID not in ('[email protected]', '[email protected]');すなわちrole_id in (3,5)

ではなく、第二部、すなわち、最初の部分のみを実行

fetchList()が含ま '[email protected]' と '[email protected]'

fetchList()の結果である:

public function fetchList($where=null, $order=null, $count=null, $offset=null) 
     { 
       $resultSet = $this->getDbTable()->fetchAll($where, $order, $count, $offset); 
       $entries = array(); 
       foreach ($resultSet as $row) 
       { 
         $entry = new Application_Model_Users(); 
         $entry->setId($row->id) 
           ->setName($row->name) 
           ->setEmail($row->email) 
         $entries[] = $entry; 
       } 
       return $entries; 
     } 

はfetchAll():

/** 
    * Fetches all rows. 
    * 
    * Honors the Zend_Db_Adapter fetch mode. 
    * 
    * @param string|array|Zend_Db_Table_Select $where OPTIONAL An SQL WHERE clause or Zend_Db_Table_Select object. 
    * @param string|array      $order OPTIONAL An SQL ORDER clause. 
    * @param int        $count OPTIONAL An SQL LIMIT count. 
    * @param int        $offset OPTIONAL An SQL LIMIT offset. 
    * @return Zend_Db_Table_Rowset_Abstract The row results per the Zend_Db_Adapter fetch mode. 
    */ 
    public function fetchAll($where = null, $order = null, $count = null, $offset = null) 
    { 
     if (!($where instanceof Zend_Db_Table_Select)) { 
      $select = $this->select(); 

      if ($where !== null) { 
       $this->_where($select, $where); 
      } 

      if ($order !== null) { 
       $this->_order($select, $order); 
      } 

      if ($count !== null || $offset !== null) { 
       $select->limit($count, $offset); 
      } 

     } else { 
      $select = $where; 
     } 
     print_r($select); 
     $rows = $this->_fetch($select); 

     $data = array(
      'table' => $this, 
      'data'  => $rows, 
      'readOnly' => $select->isReadOnly(), 
      'rowClass' => $this->getRowClass(), 
      'stored' => true 
     ); 

     $rowsetClass = $this->getRowsetClass(); 
     if (!class_exists($rowsetClass)) { 
      require_once 'Zend/Loader.php'; 
      Zend_Loader::loadClass($rowsetClass); 
     } 
     return new $rowsetClass($data); 
    } 

私は何が何をしたのか分かっています。

+0

'fetchList()'とは何ですか? – drew010

+0

@ drew010が更新しました。 – naquiuddin

+1

をチェックしてください。唯一違うところは、$ whereStringは適切に引用されたPHP文字列ではありませんが、これは質問のプレゼンテーションの理由によるものかもしれません。あなたはZend_Db_Selectのインスタンスを渡そうとしましたか? – RockyFord

答えて

0

わからないので、少し外に出ています。これは見積もり問題のように感じます。

//use Zend_Db_Statement to process raw SQL. 

//get default adapter 
$db = Zend_Db_Table::getDefaultAdapter(); 
//write SQL statement 
$sql = "select * from users where role_id in (3,5) and emailID not in ('[email protected]', '[email protected]')"; 
//assuming MySql as DB instantiate object 
$stmt = new Zend_Db_Statement_Mysqli($db, $sql); 
//Execute SQL Statement accepts optional parameter for array() of values to be bound 
$stmt->execute(); 

たり、select()のオブジェクト使用してクエリを構築したいかもしれません:

//get default adapter 
$db = Zend_Db_Table::getDefaultAdapter(); 
//instantiate the select() object 
$select = new Zend_Db_Select($db); 
$select->from('users'); 
//two where will build an AND query use $select->orWhere() to build an OR query 
$select->where('role_id in (3,5)'); 
$select->where("emailID not in ('[email protected]', '[email protected]')"); 
$result = $model->fetchList($select); 

をして$whereStringが有効なPHPの文字列、beacuseた場合、それがうまくいくかもしれないかもしれないようなあなたのクエリ文字列を渡してみてくださいfetchAll()は、Zend_Db_Selectの文字列またはインスタンスを受け入れます。

$ whereString = "(3,5)のrole_idおよび( '[email protected]'、 '[email protected]')のemailIDではありません。

これはいくつかの助けを望んでいます...私はショットを取った。

関連する問題