By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,777 Members | 1,755 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,777 IT Pros & Developers. It's quick & easy.

Mysql error

P: 36
Hi all i am new to the DBI .
when i am trying to connect to mysql using perl script i am getting the following error

Can't connect to data source '$dsn' 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)
here is the way i am tryng to connect
Expand|Select|Wrap|Line Numbers
  1. use strict;
  2.  
  3. use DBI;
  4. use DBD::mysql;
  5.  
  6. my $drh = DBI->install_driver("mysql");
  7.  
  8.  my $dsn = 'DBI:mysql:my_database:localhost';
  9.  my $dbh = DBI->connect('$dsn', 'root', '12345678',);
  10.  
Jul 1 '08 #1
Share this Question
Share on Google+
2 Replies


eWish
Expert 100+
P: 971
Here is what I use for a default connection.

Expand|Select|Wrap|Line Numbers
  1. my %config_vars = (DBServerName  => 'localhost',
  2.                     DBName                => 'xxxx',
  3.                     DBUserName         => 'xxxx',
  4.                     DBPassword         => 'xxxx',
  5.                     );
  6.  
  7.  
  8. my ($dbh, $data_source);
  9. my $dataSource = 'DBI:mysql:' . $config_vars{DBName} . ':' . $config_vars{DBServerName};
  10.    $dbh = DBI->connect( $dataSource, $config_vars{DBUserName}, $config_vars{DBPassword}, {RaiseError=>1});
--Kevin
Jul 1 '08 #2

nithinpes
Expert 100+
P: 410
I use connect() method as below:
Expand|Select|Wrap|Line Numbers
  1. $dsn = 'my_database';
  2. $host= 'localhost';
  3. my $dbh = DBI->connect( "dbi:mysql:database=$dsn;host=$host",'root','password') or die "Can't connect to mysql database: $DBI::errstr\n";
  4.  
  5.  
Jul 1 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.