Interaction with Database Servers - CGI, Servlet, PHP
Using MySQL with CGI scripts
Using MySQL with Common Gateway Interface scripts will allow you to develop more interactive web sites. Examples of using CGI scripts with MySQL are searchable catalogs, user account management, inventory tracking, and information management. Any time you have even small quantities of data which are similar and/or which will change over time, a database solution will likely be useful. Here we focused on how to program MySQL using scripting languages like Perl (CGI), PHP and JavaServlets.
A Quick Review of How CGI Works
Normally clicking on a link in a web browser causes the web server to return a static .html page. No matter who clicks on this link or how many times they do it, the resulting returned web page is always the same. To change a static .html page the site's webmaster must edit the contents of the .html file.
On the other hand, a CGI script allows a link or a button in a web page to run a program on the web server. This program can do any number of things from getting the current date and time to performing a complex lookup and update in a database. In either case, the results are not the same every time the link or button is pressed.
The process occurs something like this:
- User clicks on a link in a web page (e.g. http://doolittle.ibls.gla.ac.uk/~1007871b/COG.html).
- The web server runs the program COG.cgi.
- The COG.cgi program does what it is programmed to do.
- The COG.cgi program also builds an .html file in memory and sends it back to the user's browser.
It is the last two steps which make CGI scripts so useful. The program can perform whatever operations it needs to and it can then generate an .html page based on the results of these operations. When the CGI script is used with a database such as MySQL, many things are possible. Generally, the page returned to the user's browser contains the results of the database search. Or, if the user had provided information through a form in the web page, the database records were updated.
The COG is a code for a gene where these are held in COG-groups. e.g.: COG-group contains many Cog-codes which in turn has many Genes. In terms of Databases, the relationship would be 1 : n.
Using Perl to Access a MySQL Database
The programming language Perl can be used to access a MySQL database. It is the language we used for our examples though PHP and Servlet Database Connectivity were the other two options that were also thought. Access to MySQL using Perl requires the Perl DBI module. Both Perl and the DBI module were installed and available to use through the web site account..Follow this link for the Exercise
|Previous Topic||Next Topic|