JSP Hosting

HostingServicesSupportOrderAbout UsSoftwareHome

Even experts read the manuals. Our tech support staff has most of the books that are out on a wide variety of web topics. Here are some of their top picks. We think you'll find them useful and informative as well.

I can't access my MySQL database from my script.

Perl->MySQL database access is supported in the form of Perl's DBI module. To access your MySQL database, you'll need to include your username and password in the Perl code where you establish your connection.(You should have received a MySQL username and password with your account information.) Using the DBI module, a database connection can be established as follows:

use DBI;
$dbh = DBI->connect("DBI:mysql:yourdomain:localhost",'username',
'password',{'RaiseError'=> 1});
$sth = $dbh->prepare("select * from YOUR_TABLE");
while ($i < $sth->{'NUMROWS'}) {
$data = $sth->fetchrow;
print "$data\n";

You would substitute your domain name, username and password in the appropriate locations in the script sample above.


If you experience difficulties, check the following:

  1. Make sure your domain, username and password are spelled correctly.
  2. Make sure the table you are trying to access in your query exists.
  3. Make sure your SQL query is correct syntax (check the MySQL documentation for full syntax details).
  4. Make sure there is data in the table.

The combination of Perl and MySQL makes it easy to create dynamic web sites that perform a wide variety of tasks. To learn more about MySQL, be sure to checkout the book MySQL (New Riders, 1999).


Back To CGI-Tips


Note: MMA technical support staff cannot provide troubleshooting of problems with third-party CGI scripts including but not limited to: Perl scripts, C/C++ binaries, PHP or web/database integration unless these services are specifically contracted. For these services, please see our Quote Request Form.


Copyright © 1995-2012
Motivational Marketing Associates, LLC
All Rights Reserved.