Archive for the ‘ Perl Scripting ’ Category

Connecting To MySQL Using Perl

#!/usr/bin/perl use strict; use DBI; $host = "dbhost"; $database = "dbname"; $port = dbport; $tablename = "tablename"; $user = "dbuser"; $pw = "dbpassword"; $dbh = DBI->connect("DBI:mysql:database=$database;host=$host;port=$port",$user, $pw) or die "Unable to Connect to MySQL Server: $DBI::errstr\n"; $sql = "Sql Query Here"; $sth = $dbh->prepare($sql); $sth->execute or die "An Error Occurred: $DBI::errstr\n"; while (@row = $sth->fetchrow_array) { print "@row\n"; }