Welcome Guest, Not a member yet? Register   Sign In
How to check for success on Active Record's Class Operations
#2

[eluser]Pascal Kriete[/eluser]
AR is chainable when you're building your query. What you want to do is to check what happened once it has run. CodeIgniter makes this very easy. When a query runs it automatically saves some information about what happened (this applies to all db queries, not just AR). You can use that to your advantage to check if everything went as planned.

For the different types of queries you can check different values. Check out the query helper functions for more information.

A small list of the ones you could check depending on query type:
Code:
// INSERT
$this->db->insert_id();

// UPDATE and DELETE
$this->db->affected_rows();

// SELECT
$this->db->num_rows();

Syntax errors will trigger a CI database error to be shown, so you don't need to do anything to catch those.

Hope that helps.


Messages In This Thread
How to check for success on Active Record's Class Operations - by El Forum - 10-29-2008, 07:35 PM



Theme © iAndrew 2016 - Forum software by © MyBB