简体   繁体   English

如果没有数据更改,Codeigniter update_batch返回false

[英]Codeigniter update_batch return false if no data is changed

I have found something disturbing in codeigniter, why is when I use update_batch and the data to be updated is the exact same as the data in the db, it always return false. 我在codeigniter中发现了一些问题,为什么当我使用update_batch并且要更新的数据与db中的数据完全相同时,它总是返回false。

I can't seem to find any logical and good explanation and illustration in the CI documentation. 我似乎在CI文档中找不到任何合乎逻辑且良好的解释和说明。 I need it to return true even if there is no data changed, as it affect a great chunk of my codes, and only return false if failed to update db (ie inserting a data that already exist into a unique column), then it should return false. 即使没有数据更改,我也需要它返回true,因为它会影响我的代码中的很大一部分,并且如果更新数据库失败(即,将已经存在的数据插入唯一列中),则仅返回false。返回false。

One more thing, how do I show db query error message in CI ? 还有一件事,如何在CI中显示db查询错误消息? have read that it should be $this->db->_error_message() , but it keeps returning Call to undefined method . 已经知道它应该是$this->db->_error_message() ,但是它一直将Call to undefined method返回Call to undefined method What am I missing here ? 我在这里想念什么?

Your questions contain conflicting information: 您的问题包含冲突的信息:

  • update_batch() has never returned boolean false if it has successfully executed at least one UPDATE query, regardless of whether any records were updated or not. 如果成功执行了至少一个UPDATE查询,则update_batch() 从未返回boolean false ,而不管是否更新了任何记录。
    • In CI2, it had a void return value in that case (implicitly converted to null if you want to use it). 在CI2中,在这种情况下,它的返回值是void (如果要使用,则隐式转换为null )。
    • In CI3, it returns an integer containing the number of rows affected ( int(0) is not the same thing as bool(false) ) 在CI3中,它返回一个整数,其中包含受影响的行数( int(0)bool(false)
    • In both version trees, boolean false is only returned when you pass incorrect parameters. 在两个版本树中,仅当您传递不正确的参数时才返回布尔值false
  • _error_message() used to exist on CI2, but its underscore prefix denotes that it was an internal method and you shouldn't be using it. _error_message()曾经存在于CI2上,但是其下划线前缀表示它是一种内部方法,因此您不应该使用它。 CI3 has an error() method replacing it, which returns the code and message in an array, if there was an error in the first place. CI3有一个error()方法来替换它,如果最初出现错误,它将返回数组中的代码和消息。

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

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