开发者

Codeigniter run query before a update

I have to run a query after every update and I want to know if there is a way to automate a $this->db->query() before every $this->db->update()

I'开发者_如何学JAVAm using it for log.


you can write your own function in the file core/MY_Model.php to do that:

function queryThenUpdate($query,$update)
{
   $query = $this->db->query($query);
   //use as you need $query
   $this->db->update($update['table'],$update['data']);
}

where:

  1. $query is your actual query: SELECT * FROM ...
  2. $update is an array of two elements $update['table'] is the table to update and $update['data'] is the updating data as specified on codeigniter active record's documentation

then make every model extend MY_Model

class Your_Model extend MY_Model

and every time you need to update something:

$this->Your_Model->queryThenUpdate($query,$update)


I believe you want to use codeigniters 'hook'

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜