Introducing CMS with PHP and MySQL
Feb 1st, 2008 by admin
As a precursor to the PHP and MySQL programming tutorial, it is worth understanding that one of the most powerful uses for PHP and MySQL is as a Content Management System (or CMS). The CMS is the backbone of a good interactive web site, and all the top publishing systems, from Drupal to Wordpress use some form of server side scripting and a database. More often than not, the pair that is chosen as PHP and MySQL.
It is worth pointing out, however, that other scripting languages (such as Perl, or even C) and databases (Oracle, DB2 etc.) are available, and indeed, sometimes even better than the PHP/MySQL pairing. However, these two have traditionally been chosen because PHP is easier to program in than Perl, and MySQL is a good, stable, Open Source database platform. While this might be an over-simplification, it is true that the PHP language is aimed at power and flexibility, with an easy to understand syntax, and is therefore a great place to start web programming.
What is PHP?Following Open Source trends, PHP is a recursive acronym for PHP Hypertext Processor, and is a scripting language that allows the programmer to write code designed to be interpreted by the web server. This code can interface with back end databases, provides full programming support (decisions, loops, variables, and so on), and is commonly used to generate HTML.
A dynamic web page implemented in this way commonly contains a mixture of PHP code and HTML. The key advantages of PHP are the Open Source and true cross platform support. There are PHP builds available for Windows and Unix platforms, and the source code is available if the target platform does not have a binary build available for it.
As a CMS, PHP is most often linked to a database. This pairing allows the programmer to conditionally pull data from a database which dictates the information shown to the web user. The HTML, CSS, or XHTML layer provides the layout, and the CMS is a mixture of the two layers : information and presentation.
Where does the PHP Code go?PHP code can go in specific files (PHP files, with the common extension .php), and are presented to the browser in an URL as such. The server interprets the PHP code, and delivers a stream of information to the browser, whose job it is to interpret the stream as a web page.
However, and fairly uniquely, PHP code can also be included inside an otherwise static HTML (XML, XHTML) page. A CMS could consist of a framework of static pages, with the dynamic aspect offered by PHP used to populate the text portion of these pages, rather than a single .php file generating the entire page.
CMS Information StoragePHP provides an interface to the MySQL database system, preferred because, it too, is Open Source and provided for most platforms. It is here that the CMS will store the data used to build the pages. Everything from the text that appears, to the various graphics that might be linked to pages, maintaining the statistics, and managing user login and logout is stored in the backend database.
A CMS needs to have the following:
A way for the admin to add content; A way for users to identify the content they want to see; Categorical storage of content; Type-based storage (article, blog, etc.) of content; Statistics.The site that hosts this article is a big CMS. The content is rendered to order – only the text that makes up each article is stored. This means that, should the site administrators wish to change the look and feel, only the template should be updated. The information will still flow, just with a different presentation.
PHP is the glue that sticks the two layers together, as well as being the conduit through which the information is presented to the browser.
by Guy Lecky-Thompson
Related post

