Exercises, examples and other material relating to training module P308. This topic is presented on public courses MySQL
, Perl for Larger Projects
Perl accesses information held in relational databases through the DBI module, with additional modules (known as DBD modules) used to provide the specific code for individual database products such as MySQL. This module covers the sourcing and downloading of the DBI and DBD modules, and the use of DBI from within Perl. You don't use DBD directly, which ensures that your Perl code is very portable.
Related technical and longer articlesInterfacing applications to a MySQL database engine
|Articles and tips on this subject||updated|
|3099||Perl - database access - DBD, DBI and DBIx modules|
Perl's DBI module provides an excellent link from SQL databases to Perl, and the assorted DBD modules that fit underneath it allow it to operate well for a whole lot of different databases. But they are only excellent as far as they go - for the SQL statements have to be generated in your application ...
|2561||The future of MySQL|
MySQL has grown from a very neat little open source database 10 years ago into a very powerful and widespread database that's not always fully open source any longer today. The MySQL company was bought out by Sun a couple of years back (January 2008), and in turn Oracle are now buying Sun. This deal ...
|2381||Checking the database connection manually|
For an initial database connectivity test from my own code, I use the mysql client program and 'check out' the commands manually through that. Noting all the parameters, I then check through a piece of code in my target language ... in this brief example from Wednesday, it was Perl:
|1904||Ruby, Perl, Linux, MySQL - some training notes|
We have just come to the end of a solid 12 days of training ... and we are just getting ready for the next week, with delegates arriving this evening. There's a lot going on behind the scenes, even over this weekend, with the hotel to be prepared as well as the training course. (Picture - our clean ...
|1885||Hiding a MySQL database behind a web page|
"Keep the browser simple - with a single route in (http) to a server." That's the philosophy behind the web and one of the things that's made it a huge success. It means that a straightforward browser can contact a single server, and Joe Public, Joan Whiting and Mahatma Ali can all view content. But ...
|1224||Object Relation Mapping (ORM)|
Another technical term? Yes - this one is a formal name for how you convert a database into Objects - applicable to any OO language (Perl, Python, PHP, Java ...)
Let's reduce it to basics.
* SQL Tables become object classes
* Table rows each become individual objects
* Individual columns become attributes.
|975||Answering ALL the delegate's Perl questions|
During courses, questions arise. "I'll get back to that" could make people feel that I'm brushing something off ... except that I explain, early on, that some questions require a great deal of background knowledge to be answered sensibly. And I keep a list of topics that I'll be getting back to ...
|515||MySQL - an FAQ|
We're becoming a serious MySQL resource, with many technical articles, examples, forum posts and blog entries answering those difficult-to-resolve issues you may have come across. You might like to bookmark (or link to) this page.
Eleven recent articles on MySQL ...
Flashbulb moments - facts that ...
|644||Using a MySQL database from Perl|
Both Perl and MySQL are major pieces of open source software with a multitude of facilities available - yet you can use them together with just a tiny piece of software "glue" - the DBI and DBD::MySQL module pair from the CPAN (comprehensive Perl archive network).
Once you've got Perl and MySQL installed, ...
Examples from our training material
|D1.pl|| SQLite - DBD and DBI - create, insert, select, drop|
|D2.pl|| Adding DBIx on top of DBI and DBD - First simple example|
|D2.sql|| Sample people database|
|D2_Main.pm|| First DBIx Demonstration - headline file for loading Schema|
|D2_Main_People.pm|| Define the table to object data mapping|
|D3.pl|| Adding DBIx on top of DBI and DBD - Select on joined tables|
|D3.sql|| SQL source data for D3 demo (SQLite / DBIx / Perl)|
|D3_Main.pm|| Second DBIx Demonstration - headline file for loading Schema|
|D3_Main_Computers.pm|| Define table to object data mapping for Computers and link to people|
|D3_Main_People.pm|| Define table/object data mapping for People and how they relate to Computers|
|aclog2table|| Set up database for web access log records|
|aggy|| Connecting Perl to a MySQL database|
|dbdhash.pm|| Tie a Perl hash to a MySQL table through DBI|
|edbi|| Example using many database access methods from DBI|
|fifthdbi|| Perl DBI - display contents of MySQL table|
|firstdbi|| Simple Perl DBI Query|
|hellosql|| Accessing and SQL database with DBI and DBD modules|
|orange.pl|| DBI used in a CGI script as a GUI to a table|
|sqlping|| Using DBI and DBD to establish a connection and list available tables|
|tie_main|| Exercise - main program to die hash to database|
|trains.sql|| Data to create and populate train table for other examples|
|traintimes|| Connect to an SQL database of train times|
Some modules are available for download
as a sample of our material or under an Open Training Notes License
for free download from [here]
Topics covered in this module
Review - flat databases.
Relational databases through SQL.
Setting up the DBI and DBD modules.
Connecting to an SQL server.
Issuing an enquiry and reading back the results.
Amending information in a database via SQL.
Creating new tables.
Database support including mySQL, Oracle, Sybase, Infomix.
Interfacing Perl to the Access database.
Using Tie to access a table as if it was a Perl Hash.
If you are looking for a complete course and not just a information on a single subject, visit our Listing and schedule
Well House Consultants specialise in training courses in
. We run
throughout the UK (and beyond for longer courses), and
at our training centre in Melksham, Wiltshire, England.
It's surprisingly cost effective to come on our public courses -
even if you live in a different
country or continent to us
We have a technical library of over 700 books on the subjects on which we teach.
These books are available for reference at our training centre.