Codeigniter数据库插入失败 [英] Codeigniter Database Insert Failure

查看:102
本文介绍了Codeigniter数据库插入失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前在我的控制器中,添加新数据时,我会验证输入,如果有任何问题会告知用户,否则它将数据传递给模型以插入数据库

Currently in my controller, when adding new data, I validate the inputs, and if there are any problems it lets a user known, otherwise it passes the data to the model to insert to the database

现在我该如何检查插入语句在模型中是否正常工作,并让用户知道是否正确。

How do I now go about checking the insert statement worked correctly in the model, and let a user known if it did not.

有如下所示的插入语句,返回true或false,然后可以将其返回给控制器?

Does an insert statement like below, return true or false, which can then be returned to the controller?

$this->db->insert('Faviroute_Addresses', $address_data);

感谢您的帮助

推荐答案

您可以使用

if($this->db->insert('Faviroute_Addresses', $address_data))
{
    // Code here after successful insert
    return true;   // to the controller
}

或者您可以使用

$this->db->insert('Faviroute_Addresses', $address_data);
if($this->db->affected_rows() > 0)
{
    // Code here after successful insert
    return true; // to the controller
}

这篇关于Codeigniter数据库插入失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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