in reply to Updating or Inserting a database from a txt file

Firstly - I would suggest you remove the password on your post, secondly this is more a sql question, have you looked at using REPLACE instead of INSERT and UPDATE ?, this does depend if you have all the info you need. If not I personally would do a select on the table, then do a replace...FYI Replace will create a new record if one doesnt exist or replace the contents with what your passing if now

  • Comment on Re: Updating or Inserting a database from a txt file

Replies are listed 'Best First'.
Re^2: Updating or Inserting a database from a txt file
by cowboy (Friar) on May 10, 2005 at 16:06 UTC

    I agree, REPLACE would be better.

    If you want to use the fact the execute command failed to detect duplicate entries, you should capture the actual error code, rather than blindly trying an update on any error.

    if ($DBI::err) { if ($DBI::err eq '1062') { # taken from mysqld_error.h # duplicate.. try an update unless ($update->execute( $gamedesc, $gamename )) { die sprintf('UPDATE failed: %s %s', $gamename, $DBI::errstr); } } else { die sprintf('INSERT failed: %s %s', $gamename, $DBI::errstr); } }