如何在 Codeigniter 中检测创建、更新、删除查询是否成功 [英] How can I detect a create, update, delete query is successful in Codeigniter

查看:25
本文介绍了如何在 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()中,返回truefalse> 取决于 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:

return $this->db->update('mytable', $mydata);

这篇关于如何在 Codeigniter 中检测创建、更新、删除查询是否成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆