Connecting to a MYSQL Database using Perl
Example of updating row(s) in 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__;
update table_1
set col_2 = '$var2',
col_3 = '$var2'
where table_1.col_1 = 'X'
__CURSOR_1__
$cursor = $dbh->prepare( "$SQL_QUERY" );
$cursor->execute;
$cursor->finish;
$dbh->disconnect;