Welcome Guest, Not a member yet? Register   Sign In
[Q] How to catch SQL error?
#1

[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
#2

[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.
#3

[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
#4

[eluser]Matthieu Fauveau[/eluser]
Maybe you could use $this->db->affected_rows() to catch is the row was inserted or not ?




Theme © iAndrew 2016 - Forum software by © MyBB