registry =& $registry; } // ################################################################### /** * (PHP 4) Constructor */ function DB_MySQL(&$registry) { $this->__construct($registry); } // ################################################################### /** * Connect to a the specified database * * @access public * * @param string Server name * @param string User name * @param string Password * @param bool Use p-connect? * * @return bool Result of connect */ function connect($server, $user, $password, $pconnect) { if ($this->link_id == 0) { if ($pconnect) { $this->link_id = @mysql_pconnect($server, $user, $password); } else { $this->link_id = @mysql_connect($server, $user, $password); } if ($this->link_id == false) { $this->error('Link-Id == false, cannot connect'); return false; } if (@mysql_select_db($this->database, $this->link_id)) { return true; } else { $this->error('Cannot use the database \'' . $this->database . '\''); return false; } } } // ################################################################### /** * Send a query to MySQL * * @access public * * @param string Query string * * @return integer Resource ID for query */ function query($query_str) { $this->query_id = @mysql_query($query_str, $this->link_id); $this->query_str = $query_str; $this->history[] = $this->query_str; if (defined('ISSO_SHOW_QUERIES_LIVE')) { if (constant('ISSO_SHOW_QUERIES_LIVE')) { print($this->query_str . '
'); } } if (!$this->query_id) { $this->error('Invalid SQL query'); } return $this->query_id; } // ################################################################### /** * Escape a string depending on character set * * @access public * * @param string String to be escaped * * @return string Escaped string */ function escape_string($string) { return @mysql_real_escape_string($string, $this->link_id); } // ################################################################### /** * Fetch the query result as an array * * @access public * * @param integer Query ID * * @return array A row of the query result */ function fetch_array($query_id) { return @mysql_fetch_array($query_id, MYSQL_ASSOC); } // ################################################################### /** * Fetch the query result as an object * * @access public * * @param integer Query ID * * @return object An object with the query result */ function fetch_object($query_id) { return @mysql_fetch_object($query_id); } // ################################################################### /** * Free the current MySQL query result * * @access public * * @param integer Query ID */ function free_result($query_id) { @mysql_free_result($query_id); $this->query_id = 0; $this->query_str = ''; } // ################################################################### /** * Send a MySQL query and return the first row of the results * * @access public * * @param string Query string * @param string Result return function (in the database layer) * * @return mixed Results in variable formats */ function query_first($query_str, $callback = 'fetch_array') { $resource = $this->query($query_str); $return = $this->$callback($resource); $this->free_result($resource); return $return; } // ################################################################### /** * Fetch the unique ID of the record just inserted * * @access public * * @return integer MySQL insert ID */ function insert_id() { return @mysql_insert_id($this->link_id); } // ################################################################### /** * Fetch the number of rows in the result * * @access public * * @param integer Query ID * * @return integer Number of MySQL rows */ function num_rows($query_id) { return @mysql_num_rows($query_id); } // ################################################################### /** * Fetch the number of rows affected by the query * * @access public * * @param integer Query ID * * @return integer Number of affected rows */ function affected_rows($query_id) { return @mysql_affected_rows($this->link_id); } // ################################################################### /** * MySQL error wrapper for ISSO::_message() * * @access protected * * @param string User defined error message */ function error($message) { if ($this->errshow) { if ($this->link_id) { $this->error_no = mysql_errno($this->link_id); $this->error_str = mysql_error($this->link_id); } $style['code'] = 'font-family: \'Courier New\', Courier, mono; font-size: 11px;'; $message_prepped = "
\n

"; $message_prepped .= "\n\t» Query:\n

" . htmlspecialchars($this->query_str) ."
\n
"; $message_prepped .= "\n\t» Error Number: " . $this->error_no . "\n
"; $message_prepped .= "\n\t» Error Message: " . $this->error_str . "\n
"; $message_prepped .= "\n\t» Additional Notes: " . $message . "\n
"; $message_prepped .= "\n\t» File: " . $_SERVER['PHP_SELF'] . "\n"; $message_prepped .= "\n

\n
"; $this->registry->message('Database Error in `' . $this->registry->application . '`', $message_prepped, 3); exit; } } } /*=====================================================================*\ || ################################################################### || # $HeadURL$ || # $Id$ || ################################################################### \*=====================================================================*/ ?>