ADDR Logo Effective Online Solutions
home | about us  | solutions | partners | careers | contact
1-877-528-4850 |   Chat with a Rep   |   Order Now Help Center   |   Control Panel 
 
  HELP CENTER
 
Getting Started
FAQ - List of Frequently Asked Questions
How Tos
I am having a problem with...
Explanation of features
For advanced users
Glossary of terms
Searching
Quick submission forms for setup requests and reporting problems
 
Your Question Was...
  How do I connect to a mySQL database using CGI?
 
The script below is an example of how you may connect to a mySQL database using CGI. You may also use it to test connectivity to your database. Remember to substitute your own information as necessary, for your particular database configuration. The $DBHost variable MUST remain as stated at this point in time in order to connect to the mySQL server.

This script requires permissions of: 755.


#!/usr/bin/perl -Tw

use CGI qw(:standard);
use DBI;
use strict;

my $PageTitle = "CGI -> mySQL Test";

my $DBName = "(your database name)";
my $DBUser = "(your database user name)";
my $DBPass = "(your database password)";
my $DBHost = "mysql.addr.com";

print header,
start_html($PageTitle), "\n",
h1($PageTitle), "\n";

my $dsn = "DBI:mysql:$DBName;$DBHost";
my $dbh = DBI->connect($dsn, $DBUser, $DBPass);

if ( !defined $dbh )
{
print "\nDatabase connectionfailed\n\n";
print end_html, "\n";
exit;
}
else
{
print "\nConnection to mySQL database successful.\n\n";
}

$dbh->disconnect;

print end_html, "\n";

 
 
 
CONTROL PANEL  
Username
Password
 
CORPORATE INFO
AT A GLANCE STATS
  Pages served today:
15725733
Emails processed today:
1577412
Today's new clients:
106
 
HELP CENTER    
  1-877-528-4850
  Live Chat
  We'll Call You
SITE MAP  
 TESTIMONIALS  
All Testimonials
  About ADDR.com : Web Hosting : Web Design : E-Commerce : Reseller Program : Affiliate Program : Domain Lookup : Privacy Policy : Contact Us
   Copyright © 1997 - 2007 ADDR.com, Inc. All rights reserved.