setLastQuery($sql); $resource = mysql_query($sql); if (is_resource($resource)) { while ($row = mysql_fetch_assoc($resource)) { $result[] = $row; } } return $result; } // Returns an array of field names public function getFields($table) { $fields = array(); $resource = mysql_query("SHOW COLUMNS FROM $table;"); while ($row = mysql_fetch_array($resource)) { $fields[$row['Field']] = ''; } return $fields; } private function __construct() { $this->loadSettings($this->pathToConfigFile); $conn = mysql_connect($this->hostname, $this->username, $this->password) or trigger_error('Error connecting to server: ' . $this->hostname . " " . mysql_error(), E_USER_ERROR); mysql_select_db($this->database) or trigger_error('Error selecting database ' . $this->database . " " . mysql_error(), E_USER_ERROR); } public function __destroy() { $this->close(); } public function close() { return mysql_close(); } public function getLastQuery() { return $this->lastQuery; } // Sets the last query. A private utility method. private function setLastQuery($sql) { $this->lastQuery = $sql; } private function loadSettings($path) { foreach(parse_ini_file($path) as $key => $value) { $this->$key = $value; } if (!$this->hostname || !$this->username || !$this->password || !$this->database) { trigger_error("DB class could not load settings from " . $path); } } } ?>