Chapter 24 - MySQL
Overview |
MySQL Control Panel Feature |
Examples of SQL Statements |
Quick Actions Advanced Queries | Table Properties | Table Select | Perl SQL Delete Example Perl SQL Insert Example | Perl SQL Update Example | Perl While Loop Example View Dump Database Schema | Using MySQL With CGI Scripts References and Tutorials | Back To "Manual - Table Of Contents" 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. CGI scripting does require programming experience. If you are not familiar with CGI scripting, it is suggested that you begin with the basics of forms and non database applications. There are many books available to teach you CGI programming in a number or languages. Here we will be focusing on how to program MySQL using Perl as the CGI scripting language. 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 everytime the link or button is pressed. The process occurs something like this: It is the last two steps which make CGI scripts so useful. The program can perform what ever operations it needs to and it can then generate a .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. Using Perl to Access a MySQL Database The programming language Perl can be used to access a MySQL database. It is the language we will use for our examples. Access to MySQL using Perl requires the Perl DBI module. Both Perl and the DBI module are installed and available to use through your web site account. The following code example sets up a connection the database to the www.yourwebsite.com database, prepares and executes an SQL statement, stores the result in a local variable, and then cleans up the connection.
All queries follow the same basic formula. Simply replace the SELECT statement with the
INSERT, UPDATE,
DELETE, etc. statement you wish to use. Note that
these other queries do not return records. So, the fetchrow() and assignment which follows
should be deleted for then. Many other operations such as joins, subqueries, grouping, and sorting are all supported by providing a proper SQL statement in place of the one above. ©Copyright 2000 . All Rights Reserved. The entire contents of this site is copyrighted and may not be reproduced for any purpose without prior written permission. |
Table Of Contents: Back To Index | Chapter 1 FTP Instructions | Chapter 2 SSH / Telnet | Chapter 3 Email Software Setup | Chapter 4 CGI Bin | Chapter 5 Secure Server | Chapter 6 Formmail | Chapter 7 Microsoft Front Page | Chapter 8 CGI Scripts | Chapter 9 COMING SOON | Chapter 10 COMING SOON | Chapter 11 Streaming Audio/Real Video | Chapter 12 File Manager | Chapter 13 Mail Manager | Chapter 14 Changing Passwords | Chapter 15 Site Statistics | Chapter 16 Network Tools | Chapter 17 FTP & Anon FTP | Chapter 18 SSH / Telnet | Chapter 19 Password Protect Directories | Chapter 20 Custom Error Pages | Chapter 21 MySQL | Chapter 22 Mime Types | Chapter 23 Crontab | Chapter 24 Entropy Chat | Chapter 25 Shopping Cart | Chapter 26 Search Engine Submission | Chapter 27 PGP | Chapter 28 Subdomains | Chapter 29 Archive Manager | |