At 00:40, 19990812, sungeiway wrote:
>The problem is when i write a cgi program and try to access
>mysql database from my browser, it prompt out with "Document
>contains no data". How do i going to check whether this error
>occured just because bad cgi program or DBI not functions or/may
>be DBD not function?? or mysql failed in somewhere during the
>connection.
Sungeiway, you will find good answers to this question on the
news group comp.infosystems.www.*.cgi.
But I will give you a not-so-good answer, perhaps.
First, get this CGI script to work:
------------- Cut here -------------------------
#!perl
print "Content-type: text/plain\n\nIt works.\n";
exit 0;
------------- Cut here -------------------------
Once that works, get this one working:
------------- Cut here -------------------------
#!perl
use CGI ':standard';
print header(), "It works.<br>\n";
exit 0;
------------- Cut here -------------------------
Now, try this:
------------- Cut here -------------------------
#!perl
use CGI ':standard';
use DBI;
# you may need to change these values
my $dbname = 'test';
my $user = '';
my $password = '';
print header();
my $dbh = DBI->connect("DBI:mysql:$dbname", $user, $password);
unless ($dbh) {
print "could not connect to database: $DBI::errstr\n";
exit 1;
}
$dbh->disconnect();
print "It works.<br>\n";
exit 0;
------------- Cut here -------------------------
You now have a script that is connecting to the database. You
have eliminated, step by step, all of the problems you have had,
and you feel tired, but happy, knowing that the same method of
reducing a problem to its simplest parts and dealing with each
part individually will enable you to handle any task you may
stumble into up ahead.
THE END.
(Tim)