Welcome Guest, Not a member yet? Register   Sign In
Database class - catch insert error
#1

[eluser]Zeff[/eluser]
Hi all,

When I use
Code:
$this->db->insert('mytable', $mydata)
to insert data into a mysql table, sometimes I get an error like
Code:
'A Database Error Occurred ... Error Number: 1062 ... Duplicate entry 'zeff' for key 1'
, because I don't use an autoincrement primary key but just a unique varchar field.
I have read that 'write' actions only return true or false, but isn't there a manner to intercept the 1062 error code and show the user a nicely styled paged saying 'the record already exists'?

Many thanks in advance!

Zeff


Messages In This Thread
Database class - catch insert error - by El Forum - 06-09-2011, 02:28 AM
Database class - catch insert error - by El Forum - 06-09-2011, 04:21 AM



Theme © iAndrew 2016 - Forum software by © MyBB