PhpRiot
Follow phpriot on Twitter
Sponsored Link
Download Article
Download this article in PDF format with all listings and files.

Price: $5.00 AUD
(Approx. $5.00 USD)

More information
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store
Free iPad/iPhone App
Available on the App Store

  • PHP manual
  • Zend Framework manual
  • Smarty manual
  • PHP articles
  • PHP training

Advanced OOP With SPL In PHP 5

Implementing The IDataBaseBindings Interface

To implement the above class create a new file called PostgreSQL.php. Its contents will look something like this:

Listing 2 PostgreSQL.php
<?php
    /**
     * PostgreSQL implementer for IDataBaseBindings.
     *
     * Implements all members indicated by the interface and
     * optimizes queries for the PostgreSQL database.
     *
     * @author      Kevin McArthur
     * @depends     UnbufferedAssociativeResultSet, IDataBaseBindings
     * @implements  IDataBaseBindings
     */
    class PostgreSQL implements IDataBaseBindings
    {
        public function __construct() {
            // Create Database Connections
        }
 
        /**
         * getCustomerDetails
         *
         * Gets customer data from userDetails specified by userid
         *
         * @see IDatabaseBindings
         */
        public function getCustomerDetails($userid)
        {
            $queryResult = pg_query('select * from userDetails where userid = '. $userid . ';');
            return new UnbufferedAssociativeResultSet($queryResult);
        }
 
        public function __destruct()
        {
            // Destroy Database Connections
        }
    }
?>

The above code creates a new class called PostgreSQL that implements the getCustomerDetails() method.

This method should be responsible for doing all queries and not have any database unspecific logic. Simply retrieving or setting values in the database directly.

In This Article