467,104 Members | 1,065 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,104 developers. It's quick & easy.

Mysql error

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
  • viewed: 1633
Share:
2 Replies
eWish
Expert 512MB
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 256MB
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.

Similar topics

reply views Thread by Kenneth Illingsworth | last post: by
reply views Thread by Kenneth Illingsworth | last post: by
3 posts views Thread by c_chen | last post: by
2 posts views Thread by Elmar Grandel | last post: by
6 posts views Thread by Justin.Voelker | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.