Connecting to a MYSQL Database using Perl
Example of inserting a new row into a table
#!/usr/bin/perl
use DBI;
$|=1;
$dsn = "DBI:mysql:mydatabase;localhost";
$dbh = DBI->connect($dsn, 'username', 'password');
if ( !defined $dbh ) {
exit;
}
# use the four lines below if the query results
# in many rows or if you get 'out of memory' errors
#$SQL_QUERY="SET SQL_BIG_TABLES=1";
# $cursor = $dbh->prepare( "$SQL_QUERY" );
# $cursor->execute;
# $cursor->finish;
$SQL_QUERY=<<__CURSOR_1__;
insert into table_1 (col_1, col_2, col_3)
values ('$var1','$var2','$var3')
__CURSOR_1__
$cursor = $dbh->prepare( "$SQL_QUERY" );
$cursor->execute;
$cursor->finish;
$dbh->disconnect;