• Why you will love PHP5!

    0
    scissors
    May 25th, 1970PaulUncategorized

    If 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

    • Share/Save/Bookmark
    • Share/Save/Bookmark




Leave a Reply

Clickcha - The One-click Captcha