简体   繁体   English

mysql数据库更新和codeigniter行受影响的功能

[英]mysql database update and codeigniter rows affected function

I am using this function this codeigniter function after update query 我在更新查询后使用此函数这个codeigniter函数

$this->db->affected_rows();

it returns number of rows affected if i update values, but if i update values with the same as previous it retuns 0 rows affected 如果我更新值,它会返回受影响的行数,但如果我更新与之前相同的值,则会返回受影响的0行

Any help... 任何帮助......

yes i understand what i need is the confirmation that query has successfully run. 是的,我明白我需要的是查询已成功运行的确认。

All CI database functions return a result if they "successfully run". 如果“成功运行”,则所有CI数据库函数都会返回结果。

So 所以

$result = $this->db->update('your_table', $data);
if ( ! $result)
{
     // Error
}
{
     // Function ran ok - do whatever
}

In order to check that the database query succeeded, you can check the error code by using: 为了检查数据库查询是否成功,您可以使用以下命令检查错误代码:

$this->db->_error_message();

If that is empty, you had no error. 如果是空的,则没有错误。 If not, you have the error message. 如果没有,您有错误消息。 _error_number() is also set, so you can use that instead if you are looking for a particular error. _error_number()也已设置,因此如果您正在查找特定错误,则可以使用它。

Generally, you can skip the error check if you know there were affected_rows() , so you can limit the _error_message() test to situations where affected_rows() returns 0. 通常,如果您知道有affected_rows() ,则可以跳过错误检查,因此可以将_error_message()测试限制为affected_rows()返回0的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM