I have an array I want to check whether the username and Email values exists in database, if it does not exist insert the username and email values in the database. Using Multi insert since there are around 80000 inserts to be preformed.
$arr1 = Array
(
[0] => Array ( [Username] => uname1, [Email] => email1 )
[1] => Array ( [Username] => uname2, [Email] => email2 )
[2] => Array ( [Username] => uname3, [Email] => email3 )
)
A SQL statement with 80000
INSERTs will function slower than 80000 separateINSERTs, because the monolithic, multi-INSERTSQL statement-string won’t need to be built. For overwriting existing rows, you will need a primary key to ensure that duplicate records are overwritten: http://dev.mysql.com/doc/refman/5.1/en/replace.html.My code assumes that
Usernameis the primary key. If not, add to theSETclause to include the primary key. IfUsernameis your primary key, consider using an integer-based one as primary keys based on strings are slow.