In order to connect with a mySQL DB in perl, you're going to need to install the DBI/DBD modules.. they
may come with newer installs of perl, but I don't know for certain. The INSTALL and README files in the module archives will tell you exactly what components you need to install..
The DBI package:
http://cpan.uwinnipeg.ca/dist/DBI
The DBD-mysql driver package:
http://cpan.uwinnipeg.ca/dist/DBD-mysql
I feel like there's one more thing that needs to be installed, but it's escaping me at the moment.. the README/INSTALL's for the DBI and DBD-mysql will tell you everything that you'll need installed.
As for perl, making a connection is pretty easy:
Code:
use DBI;
my($sqlDBName) = 'geography';
my($sqlDBUser) = 'Steve';
my($sqlDBpass) = 'getstuffed';
my($db) = DBI->connect("DBI:mysql:$sqlDBName", $sqlDBUser, $sqlDBPass) or
die "Error connecting to $sqlDBName: ", $DBI::errstr, "\n";
Then create your query string, prepare it, then execute it:
Code:
my($query) = "SELECT * from country";
my($call) = $db->prepare($query);
if(!defined($call)) {
die "Prepare failed on query '$query'.\n",
"Reason: ", $db->errstr, "\n";
}
else {
if(!$call->execute()) {
die "Execute failed on query '$query'.\n",
"Reason: ", $db->errstr, "\n";
}
}
Then, it's a matter of looping through the results, depending on whether you want to use an array or a hash.
You can take a look at
here at the manpage of DBD-mysql for more examples and information about the connection.
Another question is, when you say beginner, does that mean in perl, with CGI's or what?