dbtype = $dbtype; $this->host = $dbhost; $this->username = $user; $this->password = $pass; $this->db = $database; $this->dbtype = $dbtype; switch ($this->dbtype) { case "mysql": $this->cid = @ mysql_connect($dbhost, $user, $pass); if (!$this->cid) { $this->error("mysql_connect()", "Could not connect to database server."); return false; } if ($database) { return $this->changeDB($database); } else { return true; } break; } } /** * Terminate script if we're running debug, otherwise just save the error */ function error($query, $error) { $this->lasterror = $error; if ($this->debug) { exit("Error running query:

$query

Server said:

$error
"); } } /** * Switched to the specified database name. * @param string $database The name of the database to use * @return bool True if the database was successfully selected */ function changeDB($database) { switch ($this->dbtype) { case "mysql": if (@mysql_select_db($database, $this->cid)) { $this->db = $database; return true; } else { $this->error("mysql_select_db()","Error switching to database $database"); return false; } break; } } /** * Disconnect from the database server * */ function close() { switch ($this->dbtype) { case "mysql": return mysql_close($this->cid); break; } } /** * Executes an SQL query without storing the result. Useful for INSERT, UPDATE, etc * @param string $sql The SQL code to execute * @param bool $returnid If true, returns the last insert ID (only supported * on mysql,) * @return The result handle, or if $returnid is true, the last insertid */ function sqlExec($sql, $returnid = false) { switch ($this->dbtype) { case "mysql": $result = @mysql_query($sql, $this->cid); if (!$result) { $this->error($sql, mysql_error()); } return ($returnid ? mysql_insert_id($this->cid) : $result); break; } } /** * Executes an SQL query and stores the result. * @param string $sql The SQL code to execute * @param string $set The optional set name to store the results in. By * default, the name is "default". Only one result * set can be stored with the same name at a time. */ function sqlResult($sql, $set = "default") { switch ($this->dbtype) { case "mysql": if (!($this->result[$set] = @mysql_query($sql, $this->cid))) { $this->error($sql, mysql_error()); } return $this->result[$set]; break; } } /** * Executes an SQL query and gets only one row * @param string $sql The SQL code to execute */ function sqlRow($sql, $type = MYSQL_BOTH) { switch ($this->dbtype) { case "mysql": if (!($result = @ mysql_query($sql, $this->cid))) { $this->error($sql, mysql_error()); } return @ mysql_fetch_array($result); break; } } /** * Puts the next row into an associative array. * @param mixed $set Optional result set identifier. The set "default" * is used if none is specified. * @return An array containing the next row, or False if there are no more rows */ function getRow($set = "default") { switch ($this->dbtype) { case "mysql": return @ mysql_fetch_array($this->result[$set]); break; } } /** * Finds the number of rows in the result set * @param mixed $set Optional result set identifier. The set "default" * is used if none is specified. * @return The number of rows */ function numRows($set = "default") { switch ($this->dbtype) { case "mysql": return @ mysql_num_rows($this->result[$set]); break; } } /** * Finds the number of affected rows in the result set * @param mixed $set Optional result set identifier. The set "default" * is used if none is specified. * @return The affected number of rows */ function numAffected($set = "default") { switch ($this->dbtype) { case "mysql": return @ mysql_affected_rows($this->cid); break; } } /** raw mysql_query */ function sqlResultRaw($sql) { switch ($this->dbtype) { case "mysql": return mysql_query($sql, $this->cid); break; } } /** raw mysql_fetch_array */ function getRowRaw($result) { switch ($this->dbtype) { case "mysql": return mysql_fetch_array($result); break; } } } ?>