开发者

codeigniter ActiveRecord where statement issue

开发者 https://www.devze.com 2023-04-06 20:35 出处:网络
is have this statement and i want to make it by the Active Records wayin codeigniter DELETE FROM TABLE

is have this statement and i want to make it by the Active Records way in codeigniter

DELETE FROM TABLE 
(col1 = value AND col2 = value2 ) OR (col1 = value2 AND c开发者_如何学Col2 = value );


CodeIgniter Active Record is impractical for mixing AND's and OR's within a query.

You will likely need to construct some of the query manually, e.g. something along the lines of:

$this->db->where("col1 = $value AND col2 = $value2");
$this->db->or_where("col1 = $value2 AND col2 = $value");

Alternately, in your example where there are only two specific columns and two values, the following idea should also work:

$this->db->where_in('col1', array($value, $value2));
$this->db->where_in('col2', array($value, $value2));
$this->db->where('col1 != col2');


Try this:

$this->db->where('col1', $value1);
$this->db->where('col2', $value2);
$this->db->delete($table);


That's not the goal of active record. As name suggest active record object instance is tied to a single row in a table. If you want to do this in "active record way" you have to retrieve all the records you have to delete the database, mark them as deleted and commit changes witch is overkill. Best you can do is to get connection instance from codeignither and execute query manually.

0

精彩评论

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

关注公众号