PhpRiot
Download This Article
Download this article in PDF format with all listings and files.

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

More information
Browse Articles
Ajax (4), APC (1), CAPTCHA (1), CSS (3), Debugging (1), File Upload (1), Google (3), Google Maps (2), JavaScript (12), JSON (2), MVC (1), MySQL (7), onbeforeunload (1), OOP (1), PHP (28), PhpDoc (1), PostgreSQL (6), Prototype (11), Reflection (1), RFC 1867 (1), Robots (1), Scriptaculous (1), SEO (1), Sessions (1), SimpleXML (1), Smarty (5), SOAP (1), SPL (1), Templates (2), W3C (1), XHTML (1), Zend Framework (1), Zend_Search_Lucene (1)

PhpRiot Newsletter
Your Email Address:

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


Tagged in , ,