PERL
118
db pl
Guest on 3rd July 2022 05:14:19 PM
#!/usr/bin/perl -w
use DBI;
print "Content-Type: text/plain", "\n\n";
## user database name
$db ="mysql";
## database user name
$user = "root";
## database password
$pass = "PASSWORD";
## user hostname : This should be "127.0.0.1"
## if you want to use localhost copy /etc/hosts file to
## /webroot/etc directory
##
$host="127.0.0.1";
## SQL query
$query = "show tables";
$dbh = DBI
->connect("DBI:mysql:$db:$host", $user, $pass);
$sth = $dbh->prepare($query) or die "Can't prepare $query: $dbh->errstr\n";
$rv = $sth->execute or die "can't execute the query: $sth->errstr";
print "<h1>Perl DBI Test</h1>";
print "<p>Here is a list of tables in the database $db.</p>";
while (@row= $sth->fetchrow_array()) {
my $tables = $row[0];
}
#$rc = $sth->finish;