| Store | Cart

Help connection to mysql database

From: zilore mumba <zmu...@yahoo.com>
Tue, 25 Jun 2013 15:04:16 -0700 (PDT)
Excuse my total ignorance on the above subject. I am trying to access a mysql database via a perl script, and I came across the example below, but am not sure whether my are correctly filled (where marked ######################## below).
I would appreciate assistance to clarify what should actually go into those fileds.
Secondly when I run my script, it says $rv and $rc are used once.
Will appreciate
Zilore


print "Content-type: text/html\n\n";

## mysql user database name
$db ="IP address";         # should the IP address be here or I just put MySQL? ########################
## mysql database user name
$user = "myuser";
 
## mysql database password
$pass = "mypass";
 
## user hostname : This should be "localhost" but it can be diffrent too
#$host="localhost";
$host="localhost";  # is this ok or should I put the IP address here? ######################## 

## SQL query
$query = "show tables";
 
#$dbh = DBI->connect("DBI:mysql:$db:$host", $user, $pass);
$dbh = DBI->connect("DBI:mysql:$db:$host", $user, $pass);          # should it be DBI:mysql? or ? ########################
$sqlQuery  = $dbh->prepare($query) or die "Can't prepare $query: $dbh->errstr\n";
 
$rv = $sqlQuery->execute or die "can't execute the query: $sqlQuery->errstr";
 
print "<h3>********** My Perl DBI Test ***************</h3>";
print "<p>Here is a list of tables in the MySQL database $db.</p>";
while (@row= $sqlQuery->fetchrow_array()) {
my $tables = $row[0];
print "$tables\n<br>";
}
$rc = $sqlQuery->finish;
exit(0);
_______________________________________________
ActivePerl mailing list
Acti...@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Recent Messages in this Thread
zilore mumba Jun 25, 2013 10:04 pm
Henry Hartley Jun 26, 2013 01:25 pm
Brian Raven Jun 26, 2013 02:17 pm
Messages in this thread

Previous post: (NONE)