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:
-
use strict;
-
use warnings;
-
use DBI:
-
use DBD::mysql;
-
-
my $Host = "localhost";
-
my $DbName = "dbname";
-
my $DbUser = "username";
-
my $DbPassword = "xxxxx"; # personally, I would pull this from a config file.
-
-
$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.
Regards,
Jeff