-
May 25th, 1970UncategorizedIf you haven’t made the jump from PHP4 to PHP5 yet, here are a few reasons why you should, and why you will love it when you do!
Recently I have seen increasingly more evidence that PHP4 is on its way out. Not only has support for PHP4 been stopped by the creators, but more and more php hosting companies are phasing it out too. Recently an old host of mine made the switch causing a few of my old sites to go down until I made the relevant fixes! This evidence has finally made me go for the change, and I have no idea why I didn’t sooner…
New MySQLi extension
The new mysqli extension makes database work a lot easier. In PHP4 I used a simple database class for all my database work, now there’s no real difference between the two. Here’s an example of the new syntax and how much easier it makes event the simplest of queries - getting a row from a table.
$db = new mysqli(’localhost’, ‘username’, ‘password’, ‘database’);
$result = $mysqli->query(”SELECT * FROM table WHERE id = ‘1′”);
$row = $result->fetch_assoc();$row is now an array of that row’s information in the table. Obviously the above is a very basic example, to read up on more mysqli functions check out the PHP docs.
XML
PHP5 includes new XML handling functions, known as SimpleXML which, as the name suggests, makes working with XML a doddle! If you have an XML file to parse now all that’s needed is a call to one function and you can access any of the information very easily.
[myfile.xml]
<item>
<description>Hello!</description>
</item>$somexml = simplexml_load_file(’myfile.xml’);
$somexml is now an object that holds all the information that was in the xml file, which I can access like the following.
echo $somexml->item->description;
The above would echo out Hello!. You can also loop through results nice and easily too. Read up on more simpleXML functions in the PHP docs.
New Object Oriented features
Many changes have been made to PHP’s OOP. Anyone who has a background in using OOP languages such as Java, will know how poor PHP’s OOP has been in the past. PHP5 introduces more strict rules for defining classes and methods, including the introduction finally of public, private and restricted
-
May 24th, 1970UncategorizedWhen looking for a host for your PHP website there are a few things you should consider before you buy. Below I go over a few things to look for when choosing PHP hosting.
PHP 4 or 5?
Hosts are gradually switching to PHP 5, and now that PHP 4 development and updates have come to an end, now is the best time to make the switch yourself. If you need time to make the switch some hosts will allow you to choose between the two, although be careful as sometimes this means PHP 5 is running in CGI mode, and so is likely to take a performance hit. I would also suggest switching to MySql 5 too.
Linux/Apache
You want to be looking at Linux hosting with Apache rather than Windows hosting. Windows hosting is usually used for ASP/.NET applications, and if PHP is installed it is likely to be buggy and have poor performance. PHP is meant to be run in a Linux environment so let’s keep it that way!
Access to outside the document root
With my PHP applications I like to keep template files and other system type files outside of the document root. This is a security thing mainly, as while your files are outside the document root a visitor in a browser cannot directly access them. Some hosts don’t allow you to upload outside the document root however, and in some cases it might cause errors. I would suggest looking through a host’s knowledge base, or even better contacting them directly to make sure you can do this.
Scripting requirements
You might be using a downloaded PHP script, such as Wordpress etc, or you might be using something you’ve written yourself. Before you buy web hosting it is best to check that any scripting requirements are available. This could be GD Library for image handling, or having register globals on/off, or having PHP in safe mode or not. A downloaded piece of software will usually tell you what’s required, and if it’s not on their website contact a host directly and they should be able to help out and answer any questions.
General advice
The above advice is geared towards PHP hosting specifically, it goes without saying that in general you want to look for good uptime, speeds, web space, bandwidth, easy to use control panel, good customer service, customer feedback and of course value for money. It’s worth checking out some forums or hosting comparison sites for reviews and user ratings too.
