in reply to DBI Problem

I think your $dsn is incorrect, try: my $dsn = 'DBI:mysql:database=mydb;host=localhost';

It would be a good idea to check for errors after each DBI call. You can set that up to be automatic with the 'RaiseError' attribute in the connect() call.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: DBI Problem
by thor (Priest) on Oct 23, 2002 at 12:24 UTC
    I agree. In the original code, not so much as an error check after the initial connection. Here is the same script, with (minimal) error checking:
    #!/usr/bin/perl -w # perl modules use CGI; use DBI; use strict; use diagnostics; # setup CGI handle my $cgi = new CGI; # start HTML print $cgi->header; my $dsn = 'DBI:mysql:mydb:localhost'; my $db_user_name = 'mydbusername'; my $db_password = 'mydbpassword'; my $dbh = DBI->connect($dsn, $db_user_name, $db_password) or die "Coul +dn't connect to $dsn: $DBI::errstr"; my $sth = $dbh->prepare(qq{select user, topic, topictest from pagedata +}) or die "Couldn't prepare select: ", $dbh->errstr; $sth->execute() or die "Couldn't execute query: ", $dbh->errstr; while (my ($username, $topic, $topictext) = $sth->fetchrow_array()) { print "$username, $topic, $topictext"; } $sth->finish(); $dbh->disconnect();

    thor