Gossamer Forum
Home : General : Perl Programming :

Mysql count via SSI

Quote Reply
Mysql count via SSI
Hi all...

I'm trying to draw a table count to a static html page via ssi...
can anyone comment on the following code....
it won't work as is....your input would be appreciated.......thanks Rob

#!/usr/bin/perl


@db_connect = ("DBI:mysql:xxxxxx", "xxxxxx", "xxxxxx");
$db_table = 'Items';

$dbh = DBI->connect (@db_connect) or &cgierr ("Connection Error. Reason: " . $DBI::errstr . "\n.");

$query = qq!

SELECT count(*) as num
FROM $db_table
WHERE Validated = "Yes"
!;
$sth = $DBH->prepare ($query) or &cgierr("Unable to query database. Reason: $DBI::errstr. Query: $query");
$sth->execute or &cgierr("Unable to query database. Reason: $DBI::errstr. Query: $query");
$count= $sth->fetchrow_array;
$sth->finish();
$dbh->disconnect();

print "Content-type: text/html\n\n";
print $count;

Quote Reply
Re: Mysql count via SSI In reply to
If you are using mod_perl, then you need to localize all the variables that you are using....

Code:

my ($sth, $count, $dbh, $db_table, $query);


When you check the syntax of the script (perl -c script.extension), what does it tell you?

Regards,

Eliot Lee
Quote Reply
Re: Mysql count via SSI In reply to
Put it under 'use strict' and fix your errors and you'll find the problem.

hint: dbh
hint2: fetchrow_array returns an array, not a scalar.

Cheers,

Alex

--
Gossamer Threads Inc.