Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > BOOK: Professional PHP6
|
BOOK: Professional PHP6
This is the forum to discuss the Wrox book Professional PHP6 by Edward Lecky-Thompson, Steven Nowicki; ISBN: 9780470395097
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional PHP6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 11th, 2011, 07:37 PM
Registered User
 
Join Date: Aug 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Fatal error: Call to undefined function pg_query()

Anyone know why im getting this error? Fatal error: Call to undefined function pg_query() in C:\Users\Jonny\Desktop\xampp\htdocs\projects\php\P rofessionalPhp\class.DataManager.php on line 158

I have underlined Line 158 in the following code:

Code:
<?php

require_once('class.Entity.php');
require_once('class.Individual.php');
require_once('class.Organization.php');

class DataManager {

    private static function _getConnection() {
        static $hDB;

        if (isset($hDB)) {
            return $hDB;
        }

        $hDB = pg_connect("host=localhost port=5432 dbname=ContactManager
            user=postgres password=parkhead")
                or die("Failure connecting to the database!");
        return $hDB;
    }

    public static function getAddressData($addressID) {
        $sql = "SELECT * FROM \"entityaddress\" WHERE \"addressid\" = $addressID";
        $res = pg_query(DataManager::_getConnection(), $sql);

        if (!($res && pg_num_rows($res))) {
            die("Failed getting address data for address $addressID");
        }

        return pg_fetch_assoc($res);
    }

    public static function getEmailData($emailID) {
        $sql = "SELECT * FROM \"entityemail\" WHERE \"emailid\" = $emailID";
        $res = pg_query(DataManager::_getConnection(), $sql);
        if (!($res && pg_num_rows($res))) {
            die("Failed getting email data for email $emailID");
        }

        return pg_fetch_assoc($res);
    }

    public static function getPhoneNumberData($phoneID) {
        $sql = "SELECT * FROM \"entityphone\" WHERE \"phoneid\" = $phoneID";
        $res = pg_query(DataManager::_getConnection(), $sql);
        if (!($res && pg_num_rows($res))) {
            die("Failed getting phone number data for phone $phoneID");
        }

        return pg_fetch_assoc($res);
    }

    public static function getEntityData($entityID) {
        $sql = "SELECT * FROM \"entity\" WHERE \"entityid\" = $entityID";
        $res = pg_query(DataManager::_getConnection(), $sql);
        if (!($res && pg_num_rows($res))) {
            die("Failed getting entity $entityID");
        }
        return pg_fetch_assoc($res);
    }

    public static function getAddressObjectsForEntity($entityID) {
        $sql = "SELECT \"addressid\" FROM \"entityaddress\" WHERE " .
                "\"entityid\" = $entityID";
        $res = pg_query(DataManager::_getConnection(), $sql);
        if (!$res) {
            die("Failed getting address data for entity $entityID");
        }
        if (pg_num_rows($res)) {
            $objs = array();
            while ($rec = pg_fetch_assoc($res)) {
                $objs[] = new Address($rec['addressid']);
            }
            return $objs;
        } else {
            return array();
        }
    }

    public static function getEmailObjectsForEntity($entityID) {
        $sql = "SELECT \"emailid\" FROM \"entityemail\"
            WHERE \"entityid\" = $entityID";
        $res = pg_query(DataManager::_getConnection(), $sql);
        if (!$res) {
            die("Failed getting email data for entity $entityID");
        }

        if (pg_num_rows($res)) {
            $objs = array();
            while ($rec = pg_fetch_assoc($res)) {
                $objs[] = new EmailAddress($rec['emailid']);
            }
            return $objs;
        } else {
            return array();
        }
    }

    public static function getPhoneNumberObjectsForEntity($entityID) {
        $sql = "SELECT \"phoneid\" FROM \"entityphone\" " .
                "WHERE \"entityid\" = $entityID";
        $res = pg_query(DataManager::_getConnection(), $sql);

        if ($res) {
            die("Failed getting phone data for entity $entityID");
        }

        if (pg_num_rows($res)) {
            $objs = array();
            while ($rec = pg_fetch_assoc($res)) {
                $objs[] = new PhoneNumber($rec['phoneid']);
            }
            return $objs;
        } else {
            return array();
        }
    }

    public static function getEmployer($individualID) {
        $sql = "SELECT \"organizationid\" FROM \"entityemployee\" " .
                "WHERE \"individualid\" = $individualID";
        $res = pg_query(DataManager::_getConnection(), $sql);
        if (!($res && pgsql_num_rows($res))) {
            die("Failed getting employer info for individual $individualID");
        }

        $row = pgsql_fetch_assoc($res);

        if ($row) {
            return new Organization($row['organizationid']);
        } else {
            return null;
        }
    }

    public static function getEmployees($orgID) {
        $sql = "SELECT \"individualID\" FROM \"entityemployee\" " .
                "WHERE \"organization\" = $orgID";
        $res = pg_query(DataManager::_getConnection(), $sql);

        if (!($res && pgsql_num_rows($sql))) {
            die("Failed getting employee info for org $orgID");
        }

        if (pgsql_num_rows($res)) {
            $objs = array();
            while ($row = pgsql_fetch_assoc($res)) {
                $objs[] = new Individual($row['individualid']);
            }
            return $objs;
        } else {
            return array();
        }
    }

    public static function getAllEntitiesAsObjects() {
        $sql = "SELECT \"entityid\", \"type\" FROM \"entity\" ";
        $res = pg_query(DataManager::_getConnection(), $sql);
        if (!$res) {
            die("Failed getting all entries");
        }

        if (pgsql_num_rows($res)) {
            $objs = array();
            while ($row = pgsql_fetch_assoc($res)) {
                if ($row['type'] == 'I') {
                    $objs[] = new Individual($row['entityid']);
                } elseif ($row['type'] == '0') {
                    $objs[] = new Organization($row['entityid']);
                } else {
                    die("Unknown entity type {$row['type']} encountered!");
                }
            }
            return $objs;
        } else {
            return array();
        }
    }

}

?>
Thanks!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Fatal error: Call to undefined function mysql_pcon surendran Beginning PHP 2 May 23rd, 2006 10:41 PM
Undefined Function Error arimakidd Beginning PHP 2 November 10th, 2005 02:54 AM
Call to undefined function mysql_connect() tks_muthu PHP Databases 2 June 14th, 2005 01:23 AM
Fatal error: Call to ... domxml_open_mem() Philibuster PHP Databases 0 January 1st, 2005 10:34 PM
error Call to undefined function: query() gmanon Wrox Book Feedback 1 November 20th, 2003 06:34 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.