mySQL query connection + Perl CGI

software development

#1

I’m trying to create a Perl CGI script to access my mySQL database to pull dynamic data. However, I cannot find a way to connect. I’ve seen a couple other posts similar to this, but the answer was always found offlist and not written down to help those of us coming along later.

Please help!


#2
use DBI;

my $dbh = DBI->connect("DBI:mysql:database=my_dbname;host=mysql.yourdomain.com", "mysql_user", "mysql_password");
my $sth = $dbh->prepare("SELECT * FROM table WHERE column = ? ORDER BY blah");
$sth->execute("value");
while(my ($x, $y) = $sth->fetchrow_array) {
  do_stuff($x, $y);
}

For more details, see: http://search.cpan.org/~timb/DBI/DBI.pm


#3

Thank you so much!!!

It’s been too long since I’ve done any Perl DBI programming. This used to be second nature to me. C’est la vie!