Select Git revision
class.AddressDB.php
-
Leif Andersson authoredLeif Andersson authored
class.AddressDB.php 1.39 KiB
<?php
class AddressDB {
private static $instance;
private $PDB;
private static $database = 'NyAdresser';
private function __construct() {
global $gCms;
if (!isset($gCms)) exit;
$config =& $gCms->GetConfig();
$this->PDB = ADONewConnection($config['dbms'],
'pear:date:extend:transaction');
$result = $this->PDB->Connect($config['db_hostname'],
$config['db_username'],
$config['db_password'],
self::$database);
if ($result) {
$result = $this->PDB->Execute("SET NAMES 'utf8'");
} else {
echo "Database error!<br>" . $this->PDB->ErrorMsg();
exit;
}
}
public static function getDB() {
if (!isset(self::$instance)) {
$c = __CLASS__;
self::$instance = new $c;
}
return self::$instance->PDB;
}
public static function getFields($tableName) {
$db = self::getDB();
$query = 'select column_name from information_schema.columns where '
. 'table_schema="'. self::$database . '" and table_name=?';
$values = array($tableName);
$result = $db->Execute($query,$values);
if ($result === false) { die("Database error!<br>" . $db->ErrorMsg()); }
$fields = array();
while ($row = $result->FetchRow()) {
$fields[] = $row['column_name'];
}
return $fields;
}
}