db_host = $db_host; $this->db_port = $db_port; $this->db_user = $db_user; $this->db_pass = $db_pass; $this->db_name = $db_name; if (!$this->connection = mysql_connect($this->db_host . ($this->db_port ? ':' . $this->db_port : ''), $this->db_user, $this->db_pass)) { $this->messages .= "ER: Could not connect to database server.\n"; return false; }; if (!mysql_select_db($this->db_name, $this->connection)) { $this->messages .= "ER: Could not select database.\n"; return false; }; $this->messages .= "OK: Database connection successful.\n"; return true; } /* ---------------------------------------------------------------------------------------- */ function db_close() { // Close the database connection. if ($result = mysql_close($this->connection)) { $this->messages .= "OK: Database connection closed.\n"; return $result; } else { return $result; } } /* ---------------------------------------------------------------------------------------- */ function run_query($query) { // Run a query against the database and return an array of the results. $query_results = array(); $result = mysql_query($query, $this->connection); while ($row = mysql_fetch_assoc($result)) { $query_results[] = $row; } return $query_results; } /* ---------------------------------------------------------------------------------------- */ function new_query($query) { return mysql_query($query, $this->connection); } /* ---------------------------------------------------------------------------------------- */ function fetch_row_assoc($result) { return mysql_fetch_assoc($result); } /* ---------------------------------------------------------------------------------------- */ function num_rows($result) { // return the number of rows returned by the query. return mysql_num_rows($result); } /* ---------------------------------------------------------------------------------------- */ function html_table($query) { // run the query and output the results as a HTML table. $results = $this->run_query($query); /* start with the headers */ $table = ''; foreach ($results[0] as $key => $column) { $table .= ""; } $table .= ''; /* now create the actual rows */ foreach ($results as $row) { $table .= ''; foreach ($row as $key => $value) { $table .= ""; } $table .= ''; } /* close the table */ $table .= '
$key
$value
'; return $table; } } /* ---------------------------------------------------------------------------------------- */ function escape_array(&$item, $key = '') { if (get_magic_quotes_gpc()) { $item = stripslashes($item); } $item = mysql_escape_string($item); } ?>