G Saunders Home Page EBUS202 Home Page

Database Programming for a LAMP Stack

Deliverables (See class' page for due dates):

Log into mysql _after_ you've logged into info250.us and have a bash prompt. For these exercises the command to get to the SeSPoP database with MySQL is:

         mysql -usespop -psespop SeSPoP

The sespop user id gets 'select only' privileges on the SeSPoP database, can also be used in the PHP scripts.

The next few classes are an intro to Database Programming for the Web starting with the M-MySQL/MariaDB in LAMP and one of the options for P-PHP.

Server-side Scripting with PHP

Use w3schools.com, Server Scripting, Learn PHP as your introductory text to Web Programming with PHP. (Prior work with PHP was for CLI -- Please do not run CLI scripts from the web!)   Visit us2.php.net often for detailed stuff about PHP.   

Here is a link to Discussion of the Sample Scripts. Use this for explanation of the PHP language features.

Use the docs at us2.php.net, fastest US mirror, for more details about each PHP language element.

Development Environment for Web Work

Noobs, use vi and the command line for these projects, become comfortable navigating and editing as you get your code.

Advanced students may pick another editor: It _must_ do syntax highlighting and it _must not_ be an 'HTML Editor' like DreamWeaver or Seamonkey. vi works fine if you like it, does syntax highlighting and is quickest if you have good bandwidth. It might be time to learn emacs, which is the ultimate geekish server-side editor and is on most *ix servers, will really impress a technical interviewer in the future. Windoze users might like NotePad++ or a higher functioning editor like Atom, Crimson, or Sublime where you edit on the desktop and use FileZilla to transfer files to the server via sftp (NotePad++ will automate this step if you edit its settings). Mac users should check out CodeWrangler, which handles the publishing of files to the server automagically via sftp and also has vertical marks that help align structures in html or scripts.

It's imperative to keep an eye on the error_log to make sure your html and/or scripts are not producing warnings or errors! Keep a terminal window open that's 'tailing the log' with:

tail -f /var/log/httpd/error_log | grep yourid

Keep this peeking out from under your browser so you can see it jump when you get an error!

Here is a screenshot showing such an arrangement of putty sessions and browser:


Database programming for the web is an inherently complex task involving multiple skills, data structures, and programming languages. Careful attention to error messages from the server and browser is required. The database needs to be quickly available to test SQL statements used in the scripts, to see the effect SQL in the scripts has on the database, and to delete trashed records or make changes to the schema.

The more a programmer can _see_ of these rather abstract components as they work, the easier the work becomes. One way to keep the components visible is to use have two or three putty or terminal sessions running so keep code, server httpd errors, and the database quickly available. To see browser side/JavaScript errors keep FireFox or Chrome's developer tools -> error console available.

G Saunders,
Dept of Information Systems
VCU School of Business

G Saunders Wings

Content © 1999 - Today
By G Saunders
Images are Available on the Web