PHP is a really popular web applications development language that is very accessible to both amateur and advanced programmers. Unfortunately many php developers have not received much formal training or experience in software development, so there's a lot of scary PHP code out there that is really hard to maintain and extremely difficult to customize look and feel.
It sort of goes without saying that writing code and making web pages look good are two very different skill sets. I'm a decent coder, but don't ask me to use photoshop or do CSS. When I write an application I turn over to design experts to make it look pretty. So as a rule, I want to let them do their job exposing them to as little of the PHP code as possible. As a result, they don't waste time reading code they can't modify and there is much less risk of a design change breaking your application.
What follows is a list of "Best Practices" that I use when I write PHP applications:
The sample application is tracking a list of URL's in a database. The page that we'll examine in particular is that page that "adds a link" to the list of links in a container. Categories are added into the table assuming the user entered comma separated valued list of categories for this bookmark.
| Table | Description |
| links | Table containing URL's that will be stored in a "bookmarks" database. Containter+url make up the unique key to this table. |
| categories | Table indicating the categories applied to an entry in the links table. |
| containers | Table defining a container of links. |
| File | Type | Description |
| addlink.php | Front-End | The form used for adding a bookmark link |
| inc/addlink.inc.php | Code-behind | Contains data binding, "post" processing and rendering functions used in the addlinc.php front-end page. |
| inc/links.sql.php | SQL Include | Contains function definitions for selecting, inserting and adding links to the "bookmarks" database. This file is included by almost all of the application. |
| inc/containers.sql.php | SQL Include | Contains function definitions for selecting, inserting and adding containters to the "bookmarks" database. This file is included by almost all of the application. |