Welcome Guest, Not a member yet? Register   Sign In
$query->affected_rows() (Active Record) ?

I've looked over the manual trying to find a way to test if an insert or update statement actually went through using active record.

I cannot find material related to this question.

I'm running on zero sleep and too much coffee so if I over looked it don't shoot me Smile

Thanks in advance for the assistance.

[eluser]Armchair Samurai[/eluser]
Try $this->db->affected_rows().


Cheers to you sir.

Cavaet: affected_rows() returns > 0 ONLY if a change is made to the fields in question after an UPDATE query. If no changes are made (the same data is being written back to the table entry) then the affected_rows() returns 0.

Now, is there some way to detect that the query was successful? Not that I know of. If the update occurs and there is an error, the resultant problem will be handled by the database error routine which throws that beautiful red box onto screen saying there was a database error (sorry about the redundancy).

How do we catch that error and handle it before the user sees that ugly message that halts all operations?

This affects MySQL (though it may not affect other database types).

just wanted to bump this. Same problem here. affected_rows() returns 0 if you run an update() that writes back exactly the same data that existed before. Makes sense, but like squarebones, I'd like to catch a db error.

I'd also like to know how to check if a query executed and handle it.


if($this->db->update('table',$data)) {
} else {

awesome thankyou. Smile Also, what are the errors returned as?? Can I cycle through them as an array?

[quote author="JanDoToDo" date="1264047743"]awesome thankyou. Smile Also, what are the errors returned as?? Can I cycle through them as an array?[/quote]

Looking Here:

It looks like you can specify if you want to show errors, but there's no way to get them out of CI, unless I overlooked something.

Theme © iAndrew 2016 - Forum software by © MyBB