[Q] How to catch SQL error? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: [Q] How to catch SQL error? (/showthread.php?tid=10282) |
[Q] How to catch SQL error? - El Forum - 07-24-2008 [eluser]makoto kuwata[/eluser] Hi all, I have a question about error handling. How to catch error of SQL statement? for example: create table items ( id integer primary key auto_increment, name varchar(32) not null unique ); $this->insert('items', array('name'=>'AAA')); // OK $this->insert('items', array('name'=>'AAA')); // Uniqueness error I want to catch this error. Is it possible? -- regards, makoto kuwata [Q] How to catch SQL error? - El Forum - 07-24-2008 [eluser]Randy Casburn[/eluser] Doesn't show_error() provide it? I actually prefer the native PHP mysql_error() because it doesn't rely on all the various configuration variations. [Q] How to catch SQL error? - El Forum - 07-24-2008 [eluser]makoto kuwata[/eluser] Thank you for your reply. [quote author="Randy Casburn" date="1216975553"]Doesn't show_error() provide it? I actually prefer the native PHP mysql_error() because it doesn't rely on all the various configuration variations.[/quote] I think show_error() is not a solution for this case, because $this->db-insert() doesn't return control to my code when error raise. (I'm using PHP4.) Is there any other hints? -- regards, makoto kuwata [Q] How to catch SQL error? - El Forum - 07-25-2008 [eluser]Matthieu Fauveau[/eluser] Maybe you could use $this->db->affected_rows() to catch is the row was inserted or not ? |