Connect to database using perl
dbi, perl
Solution
DBI is flexible in that it supports multiple database servers (MySQL, Sybase, Oracle, etc). The first parameter you pass in to DBI->connect is a DSN (Data Source Name), not a database name. The format of the DSN is:
`dbi:Driver:databasename`
If your database is MySQL, you would use `mysql` for the driver:
`dbi:mysql:databasename`
Here's more info on DBI.
Problem
I have one script in which I am connecting to database and trying to eexecute the sql query. My code is like this ``` use DBI; $dbh = DBI->connect('Databasename', 'uid','pswd'); my $sth = $dbh->prepare ("select * from Tablename"); $sth->execute(); my @row_ary = $sth->hetshrow_array; foreach $item (@row_ary) { print "$item\n"; } ``` when I am trying to execute this code I am getting the following error message ``` Can't connect to data source 'Databasename' because I can't work out what driver to use (it doesn't seem to contain a 'dbi:driver:' prefix and the DBI_DRIVER env var is not set) at demo.pl line 2 ``` Can anybody please suggest me why I am getting this message. What is the configuration I need to do for executing sql queries. Thanks