Connect to MySQL database with perl script :
You can connect with a MySQL database using some defined code and put it into your file and get connect easily with database :
Code:
#!/usr/bin/perl
use DBI;
$database = "DBNAME";
$hostname = "DBSERVER";
$port = "3306";
$username = "DBUSERNAME";
$password = 'DBPASSWORD';
$dsn = "DBI:mysql:database=$database;host=$hostname;port=$port";
$dbh = DBI->connect($dsn, $username, $password) or die("Could not connect!");
$sql = "SELECT * FROM mytable";
$sth = $dbh->prepare($sql);
$sth->execute;
while(($column1, $column2) = $sth->fetchrow_array)
{
print "C1 = $column1, C2 = $column2n";
}
$dbh->disconnect;
The required field are necessary to fill with the proper information.Where DBNAME is the name of database,DBSERVER is the name of server to which you would connect,DBPASSWORD requires absolute password for the database to be connect.
Bookmarks