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.



Accessing MySQL from Perl

Perl scripts use the DBI interface to access MySQL databases. This interface provides a simple way to add SQL searches to your scripts. To include the DBI in your script, add the DBI module to your script:

use DBI;

Establish a database connection with a DBI-> connect statement in the following format:

$dbh = DBI->connect("DBI:mysql:database-name:hostname",'username','password',{'RaiseError' => 1});

Once connected, you can use the $dbh connection to perform queries with a statement handle:

$sth = $dbh->prepare("select * from mytable");
$sth->execute();

To view the results of a query, a number of methods are available for the statement handle. The number of returned results is available using:

$sth->{'NUMROWS'};

An array of column values is available using:

@data = $sth->fetchrow;

Together you can iterate through your results:

while ($i < $sth->{'NUMROWS'}) {
print "$data[0], $data[1], $data[2]..\n";
$i++;
}

For more detailed information about MySQL, visit the MySQL web site.

 

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.