如何在Codeigniter中成功检测到创建,更新,删除查询 [英] How can I detect a create, update, delete query is successful in Codeigniter
本文介绍了如何在Codeigniter中成功检测到创建,更新,删除查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在编写类似这样的控制器方法:
I am currently writing a controller method like this:
public function delete($user_id) {
if ($this->input->server('REQUEST_METHOD')=='POST') {
$result = $this->Crm_user_model->update($user_id,
array('deleted'=>true));
if($result) {
add_flash_message('info', 'deleted');
} else {
add_flash_message('alert', 'can not delete');
}
//redirect('user/view');
}
}
但是所有结果均不返回任何结果,即使数据库(mssql)已更改.我怎么知道更新查询成功与否?
But all result return nothing, even the database(mssql) is changed. How can I know that the update query is success or not?
推荐答案
在 crm_user_model-> update()
中,返回 true
或 false
取决于CodeIgniter的 update()
函数的输出:
In crm_user_model->update()
, return true
or false
depending on the output of CodeIgniter's update()
function:
if ($this->db->update('mytable', $mydata)) {
// Do some stuff
return true;
} else {
// Do some stuff
return false;
}
或者,如果您不需要在模型中做任何其他事情,只需执行以下操作:
Or if you don't need to do anything else in your model, just do this:
返回$ this-> db-> update('mytable',$ mydata);
这篇关于如何在Codeigniter中成功检测到创建,更新,删除查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文