'%server %user %password %database', 'connect' => '%server %user %password %database', 'query' => '%link %query', 'error_num' => '%link', 'error_str' => '%link', 'escape_string' => '%link %string', 'fetch_assoc' => '%result', 'fetch_object' => '%result', 'free_result' => '%result', 'insert_id' => '%link', 'num_rows' => '%result', 'affected_rows' => '%result' ); // ################################################################### /** * Constructor */ function __construct(&$registry) { $this->registry =& $registry; // because ivars and call_user_func() are conspiring against us... foreach ($this->commands AS $key => $string) { if (strpos($string, '$this->') !== false) { $this->commands["$key"] = array($this, str_replace('$this->', '', $string)); } } } // ################################################################### /** * (PHP 4) Constructor */ function DB_Abstract(&$registry) { $this->__construct($registry); } // ################################################################### /** * Initializes the class and all subclasses under a common package name * * @access protected * * @return string The package name */ function init_as_package() { if (!defined('ISSO_DB_LAYER')) { define('ISSO_DB_LAYER', get_class($this)); trigger_error('ISSO_DB_LAYER was defined automatically by DB::init_as_package(). Define the constant yourself to remove this warning', E_USER_WARNING); } return 'db'; } // ################################################################### /** * Connect to a the specified database * * @access public * * @param string Server name * @param string User name * @param string Password * @param string Database name * @param bool Use p-connect? * * @return bool Result of connect */ function connect($server, $user, $password, $database, $pconnect) { $this->registry->check_isso_fields(get_class($this)); if ($this->dblink == false) { $this->dblink = call_user_func(($pconnect ? $this->commands['pconnect'] : $this->commands['connect']), $server, $user, $password, $database); if ($this->dblink == false) { $this->error('DB-Link == false, cannot connect'); return false; } return true; } } // ################################################################### /** * Send a query to the open database link * * @access public * * @param string Query string * * @return integer Result */ function query($string) { $this->querystr = $string; $this->result = call_user_func($this->commands['query'], $this->dblink, $string); $this->history[] = $string; if (defined('ISSO_SHOW_QUERIES_LIVE')) { if (constant('ISSO_SHOW_QUERIES_LIVE')) { print($this->querystr . '
'); } } if (!$this->result) { $this->error('Invalid SQL query'); } return $this->result; } // ################################################################### /** * Escape a string (depending on character set, if supported) * * @access public * * @param string String to be escaped * * @return string Escaped string */ function escape_string($string) { return call_user_func($this->commands['escape_string'], $this->dblink, $string); } // ################################################################### /** * Fetch the query result as an array * * @access public * * @param integer Result * * @return array A row of the query result */ function fetch_array($result) { return call_user_func($this->commands['fetch_assoc'], $result); } // ################################################################### /** * Fetch the query result as an object * * @access public * * @param integer Result * * @return object An object with the query result */ function fetch_object($result) { return call_user_func($this->commands['fetch_object'], $result); } // ################################################################### /** * Send a 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($string, $callback = 'fetch_array') { $resource = $this->query($string); $return = $this->$callback($resource); $this->free_result($resource); return $return; } // ################################################################### /** * Free the current query result * * @access public * * @param integer Result */ function free_result($result) { call_user_func($this->commands['free_result'], $result); $this->result = null; $this->querystr = ''; } // ################################################################### /** * Fetch the unique ID of the record just inserted * * @access public * * @return integer Insert-ID */ function insert_id() { return call_user_func($this->commands['insert_id'], $this->dblink); } // ################################################################### /** * Fetch the number of rows in the result * * @access public * * @param integer Result * * @return integer Number of rows */ function num_rows($result) { return call_user_func($this->commands['num_rows'], $result); } // ################################################################### /** * Fetch the number of rows affected by the query * * @access public * * @param integer Result * * @return integer Number of affected rows */ function affected_rows($result) { return call_user_func($this->commands['affected_rows'], $result); } // ################################################################### /** * Error wrapper for ISSO->message() * * @access protected * * @param string User defined error message */ function error($message) { if ($this->showerrors) { if ($this->dblink) { $this->errnum = call_user_func($this->commands['error_num'], $this->dblink); $this->errstr = call_user_func($this->commands['error_str'], $this->dblink); } $style['code'] = 'font-family: \'Courier New\', Courier, mono; font-size: 11px;'; $message_prepped = "
\n

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

" . htmlspecialchars($this->querystr) ."
\n
"; $message_prepped .= "\n\t» Error Number: " . $this->errnum . "\n
"; $message_prepped .= "\n\t» Error Message: " . $this->errstr . "\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$ || ################################################################### \*=====================================================================*/ ?>