MySQL Bug!!!
MySQL Bug!!!
I keep getting:-
Can't call method "prepare" on an undefined value at sql_test.cgi
I've tried all the user id's I can think of:
phpMyAdmin displays:-
localhost
hostlogonuser_test No tables found in database.
test has tables which function as expected using Query’s via phpMyAdmin
code:-
#!/usr/bin/perl
# sql_test.cgi
use DBI;
use CGI::Carp qw(fatalsToBrowser);
use DBI;
&ReadParse(*input);
$database_name=$input{'database_name'};
$host=$input{'host'};
$user_ID=$input{'user_ID'};
$password=$input{'password'};
$trace_level=$input{'trace_level'};
$sqlstatement=$input{'sqlstatement'};
print("Content-Type: text/html\n\n");
print << "head";
<html>
<HEAD>
<TITLE>SQL Test</TITLE>
<META name="description" content="SQL Test">
<META name="keywords" content="SQL Test">
<META NAME="ROBOTS" CONTENT = "All">
</HEAD>
<body>
head
if($database_name eq "" or $host eq "" or $user_ID eq "" or $password eq "" or $sqlstatement eq "")
{
print "<h3>ERROR missing data: SQL Test. Compare Bargains.</h3>
\n";
print "Database name==>$database_name
";
print "Host $host
";
print "user_ID==>$user_ID
";
print "password==>$password
\n";
print "SQL statement:
$sqlstatement
\n";
}
else
{
print "<h3>SQL Test. Compare Bargains.</h3>
\n";
print "Database name==>$database_name
";
print "Host $host
";
print "user_ID==>$user_ID
";
print "password==>$password
\n";
print "SQL statement:
$sqlstatement
\n";
## $drh = DBI->install_driver("mysql");
print "Drivers:-
\n";;
my @drivers = DBI->available_drivers();
die "No drivers found!\n" unless @drivers; # should never happen
### Iterate through the drivers and list the data sources for each one
foreach my $driver ( @drivers ) {
print "Driver: $driver\n";
my @dataSources = DBI->data_sources( $driver );
foreach my $dataSource ( @dataSources ) {
print "\tData Source is $dataSource
\n";
}
print "
\n";
}
#### Trace level is a number between 0 and 9 but usually 2 is sufficient.
# 0 - Trace disabled.
# 1 - Trace DBI method calls returning with results or errors.
# 2 - Trace method entry with parameters and returning with results.
# 3 - As above, adding some high-level information from the driver
# and some internal information from the DBI.
# 4 - As above, adding more detailed information from the driver.
# Also includes DBI mutex information when using threaded Perl.
# 5 and above - As above but with more and more obscure information.
if(($trace_level<0) or ($trace_level>9))
{
$trace_level=0
}
print "Trace level, error checking==>$trace_level
\n";
DBI->trace($trace_level);
#### Send to file DBI->trace($trace_level, $trace_filename);
# LOCAL MS Access test: open connection to Access database
# WAS $dbh = DBI->connect('dbi:ODBC:test');
# Recomended Perl $dbh = DBI->connect("DBI:mysql:jhdavmfk_test:localhost","jhda vmfk_","<PASSWORD HERE>");
print "SQL Statement==>$sqlstatement<==
\n";
# Database Name:Host,UserID,password
$dbh = DBI->connect('DBI:mysql:$database_name:$host,$user_ID, $ password',{RaiseError=>1, AutoCommit=>1});
# Prepare and execute SQL statement
$sth = $dbh->prepare($sqlstatement);
$sth->execute || die "Could not execute SQL statement ... maybe invalid?";
# Output database results
while (@row=$sth->fetchrow_array)
{
print "@row<hr>\n";
}
$dbh->disconnect();
}
print "</body></html>\n";
###
.....
ReadParse code works....
Thank you.
|