php - How to handle more than 1 unique index on error 1062? -


well, have table 2 unique index fields: email , doc. need alert user when duplicate key insertion detected. can using:

... catch(pdoexception $e) {     if($e->getcode() == 1062)     ...     } 

but don't know indexes triggered error. there way find out?

i found on google can via getmessage() function, appears versions of mysql return key 1, while others return name_of_key, makes difficult work with. need select before inserting? looks ugly.

thanks.

in order cross-version, need place select before insert. can safely select before insert without race, long create appropriate locks.

for best performance, use innodb , "select ... update" because features row-level locking. select ... update lock row if present or "gap" row if not. don't use select ... lock in share mode because create read locks have upgraded write locks, , deadlock happen.

if using myisam use lock table lock table 1 thread can access it. - http://dev.mysql.com/doc/refman/4.1/en/lock-tables.html


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -