How do I connect to my MySQL Database with Perl/CGI?   (published: 6/18/2003 2:53:42 PM)
Article # 183
Title How do I connect to my MySQL Database with Perl/CGI?

You should always use mysql.hosting-advantage.com as the database server

The following are variables you'll need to replace:
DBNAME
DBUSERNAME
DBPASSWORD

Sample Connection (Perl/CGI):
#!/usr/bin/perl
use DBI;

$database = "DBNAME";
$hostname = "mysql.hosting-advantage.com";
$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 = $column2\n";
}

$dbh->disconnect;

More Information
Related information
Related download(s)
Did you find this useful?  [rate this article]
This article has been viewed 307 times
Average reader rating 0 out of 10

©2003 NetFronts Inc.