..
In this article we will try to understand together how to use mysql db with Perl.
It 'should immediately precede that for this task needs the Perl DBI driver (Database Interface), or a library that allows the liguaggio to interface to our database.
Not only that, we also need the MySQL DBD module, interface or communication in our db.
Before peranto you should check on our server, DBI and DBD.
If both drivers are present we can continue.
Otherwise, before you do, you will need to install both.
Here is a small perl that uses scriptin (precisely) these drivers to enter data in our MySQL db.
Code:
#! / Usr / bin / perl-wuse DBI;
# Access data to mysql db
$ Database = "dbname"; $ User = "root"; $ Pass = "secret"; $ Driver = "DBI: mysql";# Connect to db
my $ dbh = "DBI -> connect ($ driver: database = $ database, $ user, $ pass)
or die "Can not connect!"# Insert some data into DB
$ Dbh-> do ("INSERT INTO Table (Field1, Field2) VALUES ('foo', 'bar')");# Disconnect from the db
$ Dbh-> disconnect;exit;
| |
Linux (Course)
Complete guide to open-source system. From 49 €. |
| |
MySQL (Course)
Management of open-source database. From 39 €. |
| |
PHP (Course)
Full course for creating dynamic Web sites. From 49 €. |