php 使用多个条件更新 cakephp 中的查询
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14515740/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Update query in cakephp with more than one condition
提问by rockfeather
I have a query like:
我有一个查询,如:
Update `pools` set status='2' where `pid`='1' and `uid`='2'
How do I convert this query in cakephp? i.e. I want to pass that AND condition in query which should update row containing pid='1' and uid='2'.
如何在 cakephp 中转换此查询?即我想在查询中传递那个 AND 条件,它应该更新包含 pid='1' 和 uid='2' 的行。
回答by Dipesh Parmar
UPDATEALLis all you need.
UPDATEALL是你所需要的全部。
$this->Pool->updateAll(array('status'=>2), array('Pool.pid'=>1,'Pool.uid' => 2));
For more documentation.
有关更多文档。
If you already have id for the row which you want to update then no need to use update cakephp is very much clever enough to understand it.
如果您已经拥有要更新的行的 id,那么无需使用 update cakephp 就足够聪明地理解它了。
For example.
例如。
if you have Pool.idwhich is row of record then.
如果你有Pool.id记录的那一行。
$this->data['Pool']['id'] = $pool_id;
$this->data['Pool']['uid'] = $pool_uid;
$this->data['Pool']['other_data'] = $pool_otherData;
$this->Pool->save($this->data['Pool']);
above will automatically save $pool_id row.
以上将自动保存 $pool_id 行。
回答by Php Geek
I guess this may work...Just try...
我想这可能有用……试试吧……
$this->Pool->updateAll(array('status'=>2), array('AND' => array('Pool.pid'=>1,'Pool.uid' => 2)));

