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

Re: connecting to mysql database ?

Thread Previous
From:
bob ackerman
Date:
March 4, 2002 15:15
Subject:
Re: connecting to mysql database ?
Message ID:
AF178554-2FC5-11D6-A414-003065428126@pacbell.net
don't know if this is it, but i am using"
$dbh = DBI->connect("DBI:mysql:$db_name")
		or die "Cannot connect to database". DBI->errstr;
note that is 'DBI:mysql', not 'DBD:mysql'.


On Monday, March 4, 2002, at 02:37  PM, Brian Volk wrote:

> 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;
>
>
> -- To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
>


Thread Previous


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