Guest_imported
New member
- Jan 1, 1970
- 0
Hi,
I've recently installed MySQL on my friends server that's running Win2k Adv. Server.
He has IIS (4.0 I believe, not positive though) running, and I'm trying to write a script to access a table in a DB, and just select all...
MySQL runs fine in the command prompt, but my script dies the second I try to connect the DB...
Assume that all I've done is installed MySQL and tested it from the command prompt.
Could someone please tell me how to connect to it from a script, select all, and then print it?
I'm using the following script:
----------------------------------------------
#!/usr/bin/perl
use DBI;
use CGI;
$foo = new CGI;
print $foo->header;
$dbuser = "test_user";
$dbpassword = "none";
$db_stuff = "DBI:mysql:Test_Database:";
my $dbh;
my $sth;
print "<HTML>\n";
print "<HEAD>\n<TITLE></TITLE>\n</HEAD>\n";
print "<BODY BGCOLOR=WHITE TEXT=BLACK>\n";
print "<BR>\n";
print "<CENTER>\n";
print "<FONT SIZE=+3><B>TESTING MYSQL</B></FONT><BR><BR>\n";
print "</CENTER>\n";
print "<TABLE WIDTH=500 BORDER=0 ALIGN=CENTER CELLPADDING=1 CELLSPACING=1>\n";
print "Got this far 0"; #using these just to find prob.
$dbd = DBI->connect($db_stuff, $dbuser, $dbpassword);
print "Got this far 1";
$statement = "SELECT field01, field02 FROM test_table";
print "Got this far 2";
$sth = $dbh->prepare($statement) or die "Can't prepare $statement: $dbh->errstr\n";
print "Got this far 3";
$sth->execute or die "Can't execute the query: $sth->errstr";
print "Got this far 4";
my @row;
while (@row = $sth->fetchrow_array) {
print "Got here";
$user_id = $row[0];
$member_name = $row[1];
$ph_points = $row[2];
print "<TR>\n";
print "<TD ALIGN=LEFT>" . $user_id . "<BR>\n";
print $member_name . "<BR>\n";
print $ph_points . "<BR>\n";
print "<HR WIDTH=75%>\n";
}
$sth->finish;
print "</TABLE>\n";
print "</BODY>\n";
print "</HTML>\n";
-----------------------------------------------------
The script dies the second it hits:
"$dbd = DBI->connect($dbi_stuff, $dbuser, $dbpassword);"
Could someone PLEASE help me?
I'm getting desperate.. heh
Thanx in advance for any help you may be able to provide,
Mayhem
I've recently installed MySQL on my friends server that's running Win2k Adv. Server.
He has IIS (4.0 I believe, not positive though) running, and I'm trying to write a script to access a table in a DB, and just select all...
MySQL runs fine in the command prompt, but my script dies the second I try to connect the DB...
Assume that all I've done is installed MySQL and tested it from the command prompt.
Could someone please tell me how to connect to it from a script, select all, and then print it?
I'm using the following script:
----------------------------------------------
#!/usr/bin/perl
use DBI;
use CGI;
$foo = new CGI;
print $foo->header;
$dbuser = "test_user";
$dbpassword = "none";
$db_stuff = "DBI:mysql:Test_Database:";
my $dbh;
my $sth;
print "<HTML>\n";
print "<HEAD>\n<TITLE></TITLE>\n</HEAD>\n";
print "<BODY BGCOLOR=WHITE TEXT=BLACK>\n";
print "<BR>\n";
print "<CENTER>\n";
print "<FONT SIZE=+3><B>TESTING MYSQL</B></FONT><BR><BR>\n";
print "</CENTER>\n";
print "<TABLE WIDTH=500 BORDER=0 ALIGN=CENTER CELLPADDING=1 CELLSPACING=1>\n";
print "Got this far 0"; #using these just to find prob.
$dbd = DBI->connect($db_stuff, $dbuser, $dbpassword);
print "Got this far 1";
$statement = "SELECT field01, field02 FROM test_table";
print "Got this far 2";
$sth = $dbh->prepare($statement) or die "Can't prepare $statement: $dbh->errstr\n";
print "Got this far 3";
$sth->execute or die "Can't execute the query: $sth->errstr";
print "Got this far 4";
my @row;
while (@row = $sth->fetchrow_array) {
print "Got here";
$user_id = $row[0];
$member_name = $row[1];
$ph_points = $row[2];
print "<TR>\n";
print "<TD ALIGN=LEFT>" . $user_id . "<BR>\n";
print $member_name . "<BR>\n";
print $ph_points . "<BR>\n";
print "<HR WIDTH=75%>\n";
}
$sth->finish;
print "</TABLE>\n";
print "</BODY>\n";
print "</HTML>\n";
-----------------------------------------------------
The script dies the second it hits:
"$dbd = DBI->connect($dbi_stuff, $dbuser, $dbpassword);"
Could someone PLEASE help me?
I'm getting desperate.. heh
Thanx in advance for any help you may be able to provide,
Mayhem