For the snippet you presented, assuming you've already created the table in your database, you could use the following to move the data from the flatfile db to the MySQL db:
open(ORGDB,"<$database") or die("Error opening database file.\n"); $dbh = DBI->connect( 'dbi:mysql:...', '...', '...', { AutoCommit => 1, PrintError => 0 } ) or die("Unable to connect to database: $DBI::errstr\n"); $sth = $dbh->prepare("INSERT INTO Agents (Name, Phone, Cell, Email) VA +LUES (?, ?, ?, ?)") or die("Unable to prepare SQL statement: $DBI::errstr\n"); while (<ORGDB>) { chomp; ($agent_name,$agent_phone,$agent_cell,$agent_email)=split(/\|/); $sth->execute($agent_name, $agent_phone, $agent_cell, $agent_email) or die("Unable to insert record: $DBI::errstr\n"); } close(ORGDB); $sth->finish(); $dbh->disconnect();
In reply to Re: Convert script to use MySQL
by ikegami
in thread Convert script to use MySQL
by lisaw
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |