CodeIgniter Forums
CI4 $db->query() & Model's update() Issue - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Model-View-Controller (https://forum.codeigniter.com/forumdisplay.php?fid=10)
+--- Thread: CI4 $db->query() & Model's update() Issue (/showthread.php?tid=78917)



CI4 $db->query() & Model's update() Issue - gordonblue - 03-27-2021

Dear CI fellows;

I'm using CI4.11. I'm not sure is this the correct place to report this...

I've found that there is no hints at all for an SQL UPDATE statement when using $db->query('UPDATE...'). The return value of $db->query() is always an instance of CodeIgniter\Database\MySQLi\Result, and calling of $db->affectedRows() ALWAYS return -1, no matter update successfully or no record to be updated (such as purposely delete the record ).

In addition, calling of $query->hasError() always failed with:
Code:
Call to undefined method CodeIgniter\Database\MySQLi\Result::hasError()

Is this a bug or have I overlooked somethings...?

Whereas, when using Query Builder or Model's update(), then $db->affectedRows() work correctly. However, calling of $this->update() or $builder->update() ALWAYS return true, even no record has found to be updated. According to documentation, it supposes to return false on failure.

Any idea?

Thanks.


RE: CI4 $db->query() & Model's update() Issue - InsiteFX - 03-27-2021

You can always try the CodeIgniter 4 developer version on gethub that's were the bugs are fixed.

CodeIgniter 4 Develop


RE: CI4 $db->query() & Model's update() Issue - gordonblue - 03-27-2021

All right. Thanks.  Smile