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

connecting to mysql database ?

Thread Next
Brian Volk
March 4, 2002 14:35
connecting to mysql database ?
Message ID:
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!  



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",
    $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.


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About