A Database-Driven Web Application in 18 Lines of Code
Maypole interacts directly with Apache through mod_perl. To work with Apache 2, a development library called libapreq2 needs to be fetched from the CPAN repository and installed into Perl. I downloaded libapreq2-2.04_03-dev.tar.gz from CPAN. Prior to installing the library, I upgraded the ExtUtils::XSBuilder module that ships with Perl. A single command, issued as root, suffices:
perl -MCPAN -e "install ExtUtils::XSBuilder"
If this is the first time the CPAN shell has executed, you'll be prompted to configure the local CPAN module. Be sure to select follow when asked about fetching prerequisite modules. With the module upgraded, I installed the libapreq2 library with the usual set of Perl module installation commands:
tar zxvf libapreq2-2.04_03-dev.tar.gz cd libapreq2-2.04-dev/ perl Makefile.PL make make test su make install <Ctrl-D>
The actual installation of Maypole starts by invoking the CPAN shell as root:
perl -MCPAN -e "shell"
As Maypole depends on a large collection of prerequisite CPAN modules, installation can take a while. Prior to actually asking the CPAN shell to install Maypole for you, issue the following commands to ensure that some of the more troublesome modules are dealt with:
cpan> install CGI::Untaint::date cpan> force install Class::DBI::mysql
I had to force the installation of Class::DBI::mysql as a number of tests failed, effectively aborting the automatic installation. By forcing the install, the broken tests are ignored, allowing the install to proceed. With the prerequisites dealt with, install Maypole with this CPAN command:
cpan> install Maypole
A series of automated interactions with the CPAN repository begin after this step. Keep an eye on what's going on, because at certain points, you have to respond to some self-explanatory prompts. When all was done and dusted, the most recent release of Maypole—2.04 at the time of this writing—was installed on my machine.
Returning to MySQL, I logged in as administrator and issued these commands to remove any default accounts:
mysql -u root -p mysql> use mysql; mysql> delete from user where User = ''; mysql> flush privileges;
I then created a new database, together with a user to act as owner of the data:
mysql> create database CLUB; mysql> grant all on CLUB.* to manager identified by 'passwordhere'; mysql> quit
These commands create the database, called CLUB, and add a user, called manager, to the database system. For the purposes of this article, this simple application manages data about an under-age soccer club. In addition to storing personal details about each player, the system maintains data on which players are in which squads, as well as any medical conditions players may have.
Here are the SQL files that I used to define the tables used within the CLUB database. The first file, create_player.sql, creates the player table:
create table player ( id int not null auto_increment primary key, name varchar (64) not null, date_of_birth date, address varchar (255), contact_tel_no varchar (64), squad int, medical_condition int );
The second file, create_squad.sql, creates the initial list of squads:
create table squad ( id int not null auto_increment primary key, name varchar (32) not null ); insert into squad (name) values ('--'); insert into squad (name) values ('Under 8'); insert into squad (name) values ('Under 9'); insert into squad (name) values ('Under 10'); insert into squad (name) values ('Under 11'); insert into squad (name) values ('Under 12');
The squad table is initialized to a reasonable set of default values. The third and final file, create_condition.sql, creates a list of possible medical conditions:
create table condition ( id int not null auto_increment primary key, name varchar (64) not null ); insert into condition (name) values ('--'); insert into condition (name) values ('Asthma'); insert into condition (name) values ('Epilepsy');
As with the squad table, the condition table is initialized with some default data. The data item in the squad and condition tables is called name. The significance of this point will be returned to later in this article.
Use the SQL files to create the tables within the database:
mysql -u manager -p CLUB < create_player.sql mysql -u manager -p CLUB < create_squad.sql mysql -u manager -p CLUB < create_condition.sql
As can be guessed, the CLUB database maintains data on players. Players belong to a squad and may have a medical condition.
|Making Linux and Android Get Along (It's Not as Hard as It Sounds)||May 16, 2013|
|Drupal Is a Framework: Why Everyone Needs to Understand This||May 15, 2013|
|Home, My Backup Data Center||May 13, 2013|
|Non-Linux FOSS: Seashore||May 10, 2013|
|Trying to Tame the Tablet||May 08, 2013|
|Dart: a New Web Programming Experience||May 07, 2013|
- RSS Feeds
- New Products
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Drupal Is a Framework: Why Everyone Needs to Understand This
- A Topic for Discussion - Open Source Feature-Richness?
- Home, My Backup Data Center
- New Products
- Developer Poll
- Trying to Tame the Tablet
- Tech Tip: Really Simple HTTP Server with Python
- Deceptive Advertising and
23 min 44 sec ago
- Let\'s declare that you have
24 min 41 sec ago
- Alterations in Contest Due
25 min 47 sec ago
- At a numbers mindset, your
26 min 58 sec ago
- Do not get Just Almost any
30 min 27 sec ago
- A fantastic rule-of-thumb to
31 min 50 sec ago
- Keren mastah..
1 hour 29 min ago
- mini tablet compare
2 hours 48 min ago
- Looking Good
6 hours 21 min ago
- Hey God - You may not be
10 hours 35 min ago
Enter to Win an Adafruit Prototyping Pi Plate Kit for Raspberry Pi
It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Prototyping Pi Plate Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- Next winner announced on 5-21-13!
Free Webinar: Linux Backup and Recovery
Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.
In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.