Perl mysql
You need to install DBD-mysql
Windows
Use ppm
Open cmd and type
ppm
Use library
use DBI;
Open
my $db = DBI->connect('DBI:mysql:dbname:servername:port', 'username', 'password') || die "database connect error : $DBI::errstr";
dbname is database name
servername is servername, localhost
port is connection port : 3306
You keep db connection in $db instance.
Close
$db->disconnect;
Insert example
Examaple
sub writeDB { my($db, $id_temp, $number) = @_; # table name, columns name $sth = $db->prepare("INSERT INTO test (id, number) VALUES(?,?)"); $sth->execute($id_temp, $number) or return 0; $sth->finish; return 1; }
*Basically, auto commit is enable, if you want to disable this feature, you turn off by code.
my $db = DBI->connect('DBI:mysql:dbname:servername:port', 'username', 'password', {AutoCommit => 0});