Handle DB exceptions

#1
[eluser]Noahs Arkive[/eluser]
CodeIgniter newbie...is there a way to handle DB exceptions within a Model using the database library? For example:

Code:
try {
       $this->db->insert('users', $ary_fields);
       return TRUE;
        } catch(Exception $e){
           return FALSE;
        }

The code above does not intercept the Exception within the CI_DB_active_record class, so I see an uncaught exception if there's a primary key or unique index violation, for example.

Is there any way of catching a active record exception short of sub-classing CI_DB_active_record?

Thanks. BTW: Love CodeIgniter!

#2
[eluser]Noahs Arkive[/eluser]
CodeIgniter newbie...is there a way to handle DB exceptions within a Model using the database library? For example:

Code:
try {
       $this->db->insert('users', $ary_fields);
       return TRUE;
        } catch(Exception $e){
           return FALSE;
        }

The code above does not intercept the Exception within the CI_DB_active_record class, so I see an uncaught exception if there's a primary key or unique index violation, for example.

Is there any way of catching a active record exception short of sub-classing CI_DB_active_record?

Thanks. BTW: Love CodeIgniter!
[quote author="Albert Einstein" date="1261772186"]The fear of death is the most unjustified of all fears, for there's no risk of accident for someone who's dead. [/quote]

#3
[eluser]alejandronanez[/eluser]
Can U handle Exceptions man? I have the same problem

#4
[eluser]danmontgomery[/eluser]
active record class doesn't throw any exceptions to be caught, so you would have to modify it to do so.

#5
[eluser]alejandronanez[/eluser]
Any suggestion? What did you do?

#6
[eluser]danmontgomery[/eluser]
I validate the input before I run the query, rather than relying on a query error to tell me if I'm inserting bad data.

#7
[eluser]33cent[/eluser]
[quote author="noctrum" date="1263962725"]I validate the input before I run the query, rather than relying on a query error to tell me if I'm inserting bad data.[/quote]


Can you post example of this?

#8
[eluser]alejandronanez[/eluser]
Thanks NOCTRUM Smile an example will be great.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.