Active Record class update() return ? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Active Record class update() return ? (/showthread.php?tid=5104) |
Active Record class update() return ? - El Forum - 01-06-2008 [eluser]tomcode[/eluser] Hi, Knows anybody the exact return values and types of the Active record class method update() ? The User Guide does not mention anything. The Docblock in the code pretends object. My tests give me boolean TRUE, whether or not an update has been done (sort of strange, no ?). Can there be other return values /types ? I can of course get the affected rows, but still, this puzzles me. Thanks. Active Record class update() return ? - El Forum - 01-06-2008 [eluser]axle_foley00[/eluser] As far as I'm aware when you do an update all you would need to know is if it returns TRUE (a successful update), FALSE (one that is not successful) and get the number of affected rows. I don't think it returns anything else or any other type. Active Record class update() return ? - El Forum - 01-06-2008 [eluser]tomcode[/eluser] I've been looking into the code, update returns FALSE when one of its params is invalid, but besides that, it'll return the result of the method query(), which is a pretty monster to read. It just puzzles me that it'll return TRUE if no row has been updated. Active Record class update() return ? - El Forum - 01-06-2008 [eluser]Seppo[/eluser] I donĀ“t think is wrong returning TRUE if no row was updated... the query has been successfully executed, if you want to check the affected rows, affected_rows method will do the trick Active Record class update() return ? - El Forum - 01-06-2008 [eluser]axle_foley00[/eluser] tomcode: Seppo would be correct. I just checked and as long as the query successfully gets executed (even if it doesn't update anything), it will return TRUE. Active Record class update() return ? - El Forum - 01-06-2008 [eluser]tomcode[/eluser] Thanks a lot guys. I have it now fixed for me and it should be solid. Active Record class update() return ? - El Forum - 01-07-2008 [eluser]Phil Sturgeon[/eluser] Never has for me, if nothing is updated it doesnt return TRUE. Or it least thats how its always happened for me. Its hard to work out whats going on in that DB driver library with a headache :p Active Record class update() return ? - El Forum - 01-07-2008 [eluser]tomcode[/eluser] Quote:Never has for me, if nothing is updated it doesnt return TRUE @thepyromaniac: This is very strange. Can You give Your environnement ? I'm working on WinXP under Apache/2.2.3 (Win32) PHP/5.2.0 MySQL/5.0.22 Apache/1.3.33 (Win32) PHP/4.3.10 MySQL/3.23.49 I've checked again the code: the update() method: returns FALSE or exists (with $this->db_debug enabled) if one of its params aint valid. else it 'just' returns the central query() method: returns FALSE or exists (with $this->db_debug enabled) if one of its params aint valid. returns $this->CACHE->read($sql) if cache is on returns FALSE if $this->simple_query($sql) returns false returns TRUE for write_type queries returns TRUE if param $return_object (the third one) is other than TRUE returns the created result object new 'CI_DB_'.$this->dbdriver.'_result' That's it. The comment: (which omits to mention the third param) Code: <?php I get the behaviour as decribed in the comment above. |