php - Easy way to check rows in SQL and add if not there? (over 100k rows) -
i have script adds 100,000 entries sql if doesn't exist. takes 30 hours check each row , add if doesnt exist. there easier way this?
my code uses loop, within loop this.
$query = mysql_query("select exists (select * linkdb link='$currentlink')"); if (mysql_result($query, 0) == 1){ }else{ $qry = "insert linkdb(link,title) values('$link','$title')"; $result = @mysql_query($qry); }
the code above takes long time because has go through thousands of entries. if don't check table first using select exist , use insert into, 90,000 entries added within 1 min. adds duplicate entries of same row.
please give me advice on do. these rows need updated everyday.
you're looking on duplicate key update
. add index on link
, then:
insert linkdb(link,title) values('$link','$title') on duplicate key update link=link;
with said, should not using ext/mysql
since deprecated. instead pdo
or mysqli
. better use parametrized queries prevent sql injection.
Comments
Post a Comment