2011-12-02 6 views
0

にfooというか、バーのいずれかである私は、Zend Frameworkのと、次のSQL更新クエリを記述したいと思います:Zend Frameworkのでこれを行うにはどのようにIDがXで更新クエリを作成し、名前はZF

UPDATE my_table 
SET my_field 
WHERE name = 'John' 
AND (other_field = 'foo' OR other_field = 'bar') 

+0

などの任意のアクションを呼びますか? zend-db?教義? – JellyBelly

答えて

0

モデルファイルがmy_table ..ifであると仮定して、モデルディレクトリ内にモデルファイルを作成しないとします。

<?php 

    class Yournamespace_Model_Mytable extends Zend_Db_Table_Abstract{ 

      protected $_name = "my_table"; 
     public function updateFunction(){ 
      $data = array('my_field' => 'new value to be set'); 
      $where[] = 'name = John'; 
      $where[] = '(other_field = "foo" OR other_field = "bar")';  
       $update= $this->update($data, $where);   

     } 

     } 

はちょうどあなたが使用するアダプタこの

$obj = new Yournamespace_Model_Mytable(); 
$obj->updateFunction(); 
関連する問題