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!