PHP Web Site – Using New PHP 5 Features
In my attempt to learn PHP I thought I would create a simple web site that does some basic database interaction (select, insert, update and delete), sorting and paging, keyword search, and use some of the new PHP 5 features such as OOP, exception handling and the new mysqli extension for MySQL 4.1 and above.
The web site has some features that I’ve seen elsewhere on the web such as paging, sorting data and keyword search highlighting. The hard part was finding the resources to explain how to do these techniques because no book gives you all the answers.
The new PHP 5 features I implemented can be found in any current PHP book. The OOP techniques added has the advantages such as increased code reuse, modularity and flexiblity for expansion. This style of coding has been around for a long time (like exception handling) so it was a nice addition in my opinion to PHP 5.
Though for a web site this small using OOP may not be necessary, but will give you a good example of basic syntax and basic implementation. Here are some screencasts (.zip) by Jonathan Sampson that explain PHP OOP development with the first video covering what is a class and how to create one and the second video showing you how to create private, public and protected properties within a class. The third video covers interfaces and abstractions that are not used.
Other new PHP 5 features I used were exceptions, which are a new way of handling errors in your PHP code. As with OOP, this feature has been around in other programming languages (VB.NET, C#, Java, etc.), and in my opinion a easier and better way to capture unexpected errors (i.e. database error). The last new feature was using the mysqli extension which incorporates new functionality in MySQL 4.1 and above. The changes are small (compared to mysql extension) and very easy to implement in any exisiting PHP code you may have.
I also used functions such as mysqli_real_escape_string and addslashes to help prevent against SQL injection.
There are many other issues of security that should be considered when developing web applications. Read the PHP Security Guide (.pdf) by the people at the PHP Security Consortium to learm more.





