P
poopdeville
Hi everybody.
I'm having a bit of a problem getting DBI to interface with mysql.
This is my first experience with DBI, so I'm not really sure where to
start troubleshooting. I've read several FMs, but my -> foo isn't so
great. Basically, I'm trying to pull out a column of data out of a
mysql table and printing HTML based on it. A minimal example of code
that causes trouble is:
# use DBI;
#
# my $dbh = DBI->connect('DBI:mysql:database', 'user', 'pass')
# or die "Couldn't connect to database: " . DBI->errstr;
# my $sth = $dbh->do('SELECT title FROM pages') or die
# "Couldn't query the database: " . DBI->errstr;
# while(my @title = $sth->fetchrow_array) {
# print "<option>$title[0]</option>\n";
# }
(It's commented to preserve formatting.) I get an error: Can't call
method "fetchrow_array" without a package or object reference at... the
line where the while loop starts. Can anybody help?
Thanks,
'cid 'ooh
I'm having a bit of a problem getting DBI to interface with mysql.
This is my first experience with DBI, so I'm not really sure where to
start troubleshooting. I've read several FMs, but my -> foo isn't so
great. Basically, I'm trying to pull out a column of data out of a
mysql table and printing HTML based on it. A minimal example of code
that causes trouble is:
# use DBI;
#
# my $dbh = DBI->connect('DBI:mysql:database', 'user', 'pass')
# or die "Couldn't connect to database: " . DBI->errstr;
# my $sth = $dbh->do('SELECT title FROM pages') or die
# "Couldn't query the database: " . DBI->errstr;
# while(my @title = $sth->fetchrow_array) {
# print "<option>$title[0]</option>\n";
# }
(It's commented to preserve formatting.) I get an error: Can't call
method "fetchrow_array" without a package or object reference at... the
line where the while loop starts. Can anybody help?
Thanks,
'cid 'ooh