468,316 Members | 1,981 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

how to connect in database

hi......can you please help me to connect in database using perl...what is the appropriate database to use and what is the connection string.....
thank you...
Sep 19 '08 #1
2 1190
Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use DBI;
  4. my $db = DBI->connect( 'databasename',
  5.                         'username',
  6.                         'usepassword',
  7. $db->disconnect();
Sep 19 '08 #2
3,503 Expert Mod 2GB
erpritish: The way that you have written that code it would fail. The format is incorrect and it includes an out of place disconnect all within the same statement. Also, when you post code in the forums, you really need to use the necessary code tags. There is an example of them to the right of the Reply window in the "Reply Guidelines" box. Please use them next time. Also, in these forums, we don't just provide code that is requested as this is not a scripting service. While I know you are being helpful, it does not help the OP learn.

fatimang: You are really going to want to take a look at the DBI module page on CPAN . It will tell you all that you need to know about connecting to a database. In the mean time try this:

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3. use DBI:
  4. use DBD::mysql;
  6. my $Host = "localhost";
  7. my $DbName = "dbname";
  8. my $DbUser = "username";
  9. my $DbPassword = "xxxxx"; # personally, I would pull this from a config file.
  11. $dbh = DBI->connect("dbi:mysql:host=$Host;database=$DbName", $DbUser , $DbPassword) or die;
That will at least get you connected to the database, but what you do from there is up to you. I know that I said earlier in this post that I don't normally just give out code, as it won't help you learn, but since the other OP provided you what they did, I posted this to give you a better example. Next time you will probably be asked to show the code you have tried and any errors you see as well.


Sep 19 '08 #3

Post your reply

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

Similar topics

20 posts views Thread by Mr Dygi | last post: by
3 posts views Thread by Jassim Rahma | last post: by
21 posts views Thread by Steve | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.