develooper Front page | perl.beginners | Postings from March 2002

connecting to mysql database ?

Thread Next
From:
Brian Volk
Date:
March 4, 2002 14:35
Subject:
connecting to mysql database ?
Message ID:
3C83F714.3070107@bvolk.com
Hi All,

I'm having some trouble connecting to mysql database.  Here is a copy of 
the script I'm using... One of the errors I'm getting is "no database 
driver specified".  Any help would be greatly appreciated.  Thanks!  

Brian
bvolk@bvolk.com


#!/usr/bin/perl

use DBI;

# Gather some information from the user :
print "Enter your MySQL username: ";
$username = <STDIN>;
print "Enter your MySQL password; ";
$password = <STDIN>;

# Connect to the database

my $dbh = DBI->connect ( "DBD:mysql :database=perl :host=localhost",
$username,
    $password) || die  "Couldn't connect to database";

print "Database connection established."

# Perpare statement

my $sth = $dbh->prepare( "SELECT * FROM perl_table" );

# Send statement to database

$sth->execute || die "Couldn't execute statement";

# Print out the data

my @row
while ( @row = $sth->fetchrow_array() ) {
    print "@row \n";
}

# One more thing: we need to disconnect from the database server
# when we're done.

$dbh->disconnect;


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About