topical media & game development
professional-php-03-class.DataManager.php / php
<?php
require_once('class.Entity.php'); //this will be needed later
require_once('class.Individual.php');
require_once('class.Organization.php');
class DataManager
{
private static function _getConnection() {
static hDB)) {
return hDB = pg_connect("host=localhost port=5432 dbname=sample_db user=phpuser
password=phppass");
or die("Failure connecting to the database!");
return addressID) {
addressID";
sql);
if(! (res))) {
die("Failed getting address data for address res);
}
public static function getEmailData(sql = "SELECT * FROM \"entityemail\" WHERE \"emailid\" = res = pg_query(DataManager::_getConnection(), res && pg_num_rows(emailID");
}
return pg_fetch_assoc(phoneID) {
phoneID";
sql);
if(! (res))) {
die("Failed getting phone number data for phone res);
}
public static function getEntityData(sql = "SELECT * FROM \"entities\" WHERE \"entityid\" = res = pg_query(DataManager::_getConnection(),res && pg_num_rows(entityID");
}
return pg_fetch_assoc(entityID) {
entityID";
sql);
if(!entityID");
}
if(pg_num_rows(objs = array();
while(res)) {
rec['addressid']);
}
return entityID) {
entityID";
sql);
if(!entityID");
}
if(pg_num_rows(objs = array();
while(res)) {
rec['emailid']);
}
return entityID) {
entityID";
sql);
if(!entityID");
}
if(pg_num_rows(objs = array();
while(res)) {
rec['phoneid']);
}
return individualID) {
individualID";
sql);
if(! (res))) {
die("Failed getting employer info for individual row = pgsql_fetch_assoc(row) {
return new Organization(orgID) {
orgID";
sql);
if(! (res))) {
die("Failed getting employee info for org res)) {
row = pgsql_fetch_assoc(objs[] = new Individual(objs;
} else {
return array();
}
}
public static function getAllEntitiesAsObjects() {
res = pgsql_query(DataManager::_getConnection(), res) {
die("Failed getting all entities");
}
if(pgsql_num_rows(objs = array();
while(res)) {
if(objs[] = new Individual(row['type'] == 'O') {
row['entityid']);
} else {
die("Unknown entity type {objs;
} else {
return array();
}
}
}
?>
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.