private function buildDb() { require fimport('class/db'); require fimport('class/mysql'); $class = 'FDbMySql'; if (count($this->var['config']['db']['slave'])) { require fimport('class/mysqlslave'); $class = 'FDbMysqlSlave'; } $this->db =& FDB::object($class); $this->db->setConfig($this->config['db']); $this->db->connect(); }
/** * 执行查询命令 * * @access private * @param string $cmd 查询命令 * @param mixed $arg1 参数1 * @param mixed $arg2 参数2 * @return mixed */ private function _execute($cmd, $arg1 = '', $arg2 = '') { static $db; if (empty($db)) { $db =& FDB::object(); } $res = $db->{$cmd}($arg1, $arg2); return $res; }
/** * 数据库错误 * @param string $message 错误代码 * @param string $sql 查询语句 * @return void */ function dbError($message, $sql) { global $_FANWE; list($show_trace, $log_trace) = FanweError::debugBacktrace(); $title = lang('error', 'db' . $message); $title_msg = lang('error', 'db_error_message'); $title_sql = lang('error', 'db_query_sql'); $title_backtrace = lang('error', 'backtrace'); $title_help = lang('error', 'db_help_link'); $db =& FDB::object(); $db_errno = $db->errno(); $db_error = str_replace($db->tablepre, '', $db->error()); $sql = htmlspecialchars(str_replace($db->tablepre, '', $sql)); $msg = '<li>[Type] ' . $title . '</li>'; $msg .= $db_errno ? '<li>[' . $db_errno . '] ' . $db_error . '</li>' : ''; $msg .= $sql ? '<li>[Query] ' . $sql . '</li>' : ''; FanweError::showError('db', $msg, $show_trace, false); unset($msg, $show_trace); $error_msg = '<b>' . $title . '</b>'; $error_msg .= "[{$db_errno}]<br /><b>ERR:</b> {$db_error}<br />"; if ($sql) { $error_msg .= '<b>SQL:</b> ' . $sql; } $error_msg .= "<br />"; $error_msg .= '<b>PHP:</b> ' . $log_trace; FanweError::writeErrorLog($error_msg); exit; }