in reply to Re^2: Updating or Inserting a database from a txt file
in thread Updating or Inserting a database from a txt file
When it comes to updating it alwasy about the last game of the txt file and never the rest of them?my ($gamename, $gamedesc, $gamecount); my $select = $dbh->prepare( "SELECT count(*) FROM games WHERE gamename +=?" ); my $insert = $dbh->prepare( "INSERT INTO games (gamename, gamedesc, ga +mecounter) VALUES (?, ?, ?)" ); my $update = $dbh->prepare( "UPDATE games SET gamedesc=?, gamecount=?+ +1 where gamename=?" ); open (FILE, "<../data/games/descriptions.txt") or die $!; while (<FILE>) { chomp; ($gamename, $gamedesc) = split /\t/; if ( $select->execute($gamename) ) { $update->execute( $gamedesc, $gamecount, $gamename ); } else { $insert->execute( $gamename, $gamedesc, 0 ); } } close (FILE);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Updating or Inserting a database from a txt file
by bart (Canon) on May 12, 2005 at 07:36 UTC | |
|
Re^4: Updating or Inserting a database from a txt file
by Nik (Initiate) on May 12, 2005 at 07:37 UTC |