host, $this->username, $this->password, $this->persistant, $this->database) = array($host, $user, $pass, $database, $database, $persist); if($connect) $this->connect($host, $user, $pass, $database, $persist, $new); } public function connected() { return $this->connected; } public function exec($query) { /* This will NOT return OR assign a result object */ if($this->query($query) !== false) return $this->affected(); throw(new DBException('Query execution failed.')); } } ?> resource = $result; } public function next($list=false) { $this->data = @mysql_fetch_array($this->resource, $list ? MYSQL_NUM : MYSQL_ASSOC); } public function rows() { return @mysql_num_rows($this->resource); } public function free() { @mysql_free_result($this->resource); } private function __set($indice, $value) { return $this->data[$indice] = $value; } private function __get($indice) { return isset($this->data[$indice]) ? $this->data[$incide] : null; } private function __destruct() { $this->free(); } } /* should probably be generic/abstract definition/interface, to aid in forcing further implementation, * but for these specific purposes I dont see the point in putting forth * the additional trouble - besides, theres far too many issues with PHP's implementation * of interface */ class DB extends DBa { public function connect($host=null, $user=null, $pass=null, $database=null, $persist=false, $new=false) { $this->_construct(false, $host, $user, $pass, $database, $persist, $new); if($this->connected = ( ($this->handle = $this->persistant ? @mysql_pconnect($this->host, $this->username, $this->password, $new, $this->flags) : @mysql_connect($this->host, $this->username, $this->password, $new, $this->flags) ) !== false) ? true : false) return $this->handle; throw(new DBException('Failed to establish a connection to the requested host on port ' . $port . '.'); } public function close() { return @mysql_close($this->handle); } public function select_db($db) { $this->database = $db; return $r = @mysql_select_db($this->database, $this->handle) ? $r : throw(new DBException('Failed to select database \'' . $this->database . '\'.')); } public function query($query = null) { if(!is_null($query)) $this->query = $query; /* re-execute LAST query if null */ if(($result = @mysql_query($this->query, $this->handle)) !== false) return is_resource($result) ? ($this->result = new db_result($result)) : $result; throw new DBException('Query failed.'); } public function exec($query) { /* This will NOT return OR assign a result object */ if(is_object($result = parent::exec($query))) throw(new DBException('exec(): INSERT/DELETE/UPDATE only')); else return $result; } public function insert($table, $values = array(), $data = array()) { if(!empty($values) && empty($data)) } public function affected() { return mysql_affected_rows($this->resource); } public function escape($string) { return mysql_real_escape_string($string); } public function error() { return $this->error = mysql_error(); } private function __destruct() { } } ?>