/** * Init test */ public function setUp() { try { $this->conn = DB_MySQL::connect("localhost", "qtest", null, null, null, null, array('config' => array('driver' => 'yaml', 'path' => __DIR__ . '/settings'))); } catch (Exception $e) { $this->markTestSkipped("Failed to connect to database. Please create a user 'qtest' with all privileges to database 'qtest'. " . $e->getMessage()); } $this->createTestSchema(); }
/** * Init test */ public function setUp() { try { $this->conn = DB_MySQL::connect("localhost", "qtest"); } catch (Exception $e) { $this->markTestSkipped("Failed to connect to database. Please create a user 'qtest' with all privileges to database 'qtest'. " . $e->getMessage()); } $this->createTestSchema(); }
private function storeMySql($objectID, $objectOld) { if (null === $this->_db) { $this->_db = new \Core\DB_MySQL(); $this->_db->connect($this->config->db->db_host, $this->config->db->db_name, $this->config->db->db_user, $this->config->db->db_password); } $sql = "INSERT INTO " . self::MYSQL_TABLE_NAME . " SET "; $sql .= " ActionID = '" . addslashes($this->_action) . "',"; $sql .= " Date = '" . time() . "',"; $sql .= " UserID = " . $this->_userID . ','; $sql .= " IP = '" . $this->_IP . "',"; $sql .= " ForwardedIP = '" . $this->_ForwardedIP . "',"; $sql .= " ObjectID = " . intval($objectID) . ","; $sql .= " ObjectOld = " . $objectOld . ","; $sql .= " Params='" . $this->_params . "'"; try { $this->_db->execute($sql); } catch (\Exception $e) { throw new \Core\Exception($sql, 0, null, $this->config); } }
/** * @param array $config * * @return DB_MySQL|DB_MySQLi|DB_PgSQL|DB_SQLite */ function db_connection($config) { require_once MYBB_ROOT . "inc/db_{$config['database']['type']}.php"; switch ($config['database']['type']) { case "sqlite": $db = new DB_SQLite(); break; case "pgsql": $db = new DB_PgSQL(); break; case "mysqli": $db = new DB_MySQLi(); break; default: $db = new DB_MySQL(); } // Connect to Database define('TABLE_PREFIX', $config['database']['table_prefix']); $db->connect($config['database']); $db->set_table_prefix(TABLE_PREFIX); $db->type = $config['database']['type']; return $db; }
} $nid = intval($_GET['nid']); if ($nid) { $query = "SELECT * FROM `yunbbs_categories` WHERE `id`='{$nid}'"; $c_obj = $DBS->fetch_one_array($query); if (!$c_obj) { header('location: /admin-node#edit'); exit; } } $tip1 = ''; $tip2 = ''; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $action = $_POST['action']; $DBM = new DB_MySQL(); $DBM->connect($servername_m, $dbport, $dbusername, $dbpassword, $dbname); if ($action == 'find') { $n_id = trim($_POST['findid']); if ($n_id) { header('location: /admin-node-' . $n_id); } else { header('location: /admin-node#edit'); } exit; } else { if ($action == 'add') { $n_name = trim($_POST['name']); $n_about = trim($_POST['about']); if ($n_name) { $check_obj = $DBS->fetch_one_array("SELECT * FROM `yunbbs_categories` WHERE `name`='" . $n_name . "'"); if ($check_obj) {
} function createtable($sql) { $type = strtoupper(preg_replace("/^\\s*CREATE TABLE\\s+.+\\s+\\(.+?\\).*(ENGINE|TYPE)\\s*=\\s*([a-z]+?).*\$/isU", "\\2", $sql)); $type = in_array($type, array('MYISAM', 'HEAP')) ? $type : 'MYISAM'; return preg_replace("/^\\s*(CREATE TABLE\\s+.+\\s+\\(.+?\\)).*\$/isU", "\\1", $sql) . (mysql_get_server_info() > '4.1' ? " ENGINE={$type} DEFAULT CHARSET=utf8" : " TYPE={$type}"); } if (in_array($action, array('first', 'second', 'three', 'four', 'five'))) { // 允许程序在 register_globals = off 的环境下工作 // 加载数据库配置信息 require_once SABLOG_ROOT . '/config.php'; // 加载数据库类 require_once SABLOG_ROOT . '/include/class/mysql.class.php'; // 初始化数据库类 $DB = new DB_MySQL(); $DB->connect($servername, $dbusername, $dbpassword, $dbname, $usepconnect); unset($servername, $dbusername, $dbpassword, $dbname, $usepconnect); $step = !$step ? 1 : $step; $percount = $percount <= 0 ? 500 : $percount; $start = ($step - 1) * $percount; $next = $start + $percount; $step++; $jumpurl = $php_self . '?action=' . $action . '&step=' . $step . '&percount=' . $percount; $goon = 0; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>SABLOG-X | Powered by 4ngel</title>
switch ($config['database']['type']) { case "sqlite": $db = new DB_SQLite(); break; case "pgsql": $db = new DB_PgSQL(); break; case "mysqli": $db = new DB_MySQLi(); break; default: $db = new DB_MySQL(); } // Connect to Database define('TABLE_PREFIX', $config['database']['table_prefix']); $db->connect($config['database']); $db->set_table_prefix(TABLE_PREFIX); $db->type = $config['database']['type']; // Load Settings if (file_exists(MYBB_ROOT . "inc/settings.php")) { require_once MYBB_ROOT . "inc/settings.php"; } if (!file_exists(MYBB_ROOT . "inc/settings.php") || !$settings) { if (function_exists('rebuild_settings')) { rebuild_settings(); } else { $options = array("order_by" => "title", "order_dir" => "ASC"); $query = $db->simple_select("settings", "value, name", "", $options); while ($setting = $db->fetch_array($query)) { $setting['value'] = str_replace("\"", "\\\"", $setting['value']); $settings[$setting['name']] = $setting['value'];
makehide('order', $order); p('<p>'); p('DBHost:'); makeinput(array('name' => 'dbhost', 'size' => 20, 'value' => $dbhost)); p('DBUser:'******'name' => 'dbuser', 'size' => 15, 'value' => $dbuser)); p('DBPass:'******'name' => 'dbpass', 'size' => 15, 'value' => $dbpass)); makeinput(array('value' => 'Connect', 'type' => 'submit', 'class' => 'bt')); p('</p>'); if ($dbhost && $dbuser && isset($dbpass)) { // 初始化数据库类 $DB = new DB_MySQL(); $DB->charsetdb = $charsetdb; $DB->charset = $charset; $DB->connect($dbhost, $dbuser, $dbpass, $dbname); //获取数据库信息 p('<p class="red">MySQL ' . $DB->version() . ' running in ' . $dbhost . ' as ' . $dbuser . '@' . $dbhost . '</p>'); $highver = $DB->version() > '4.1' ? 1 : 0; //获取数据库 $query = $DB->query("SHOW DATABASES"); $dbs = array(); $dbs[] = '-- Select a database --'; while ($db = $DB->fetch($query)) { $dbs[$db['Database']] = $db['Database']; } makeselect(array('name' => 'dbname', 'option' => $dbs, 'selected' => $dbname, 'onchange' => 'setdb(this.options[this.selectedIndex].value)')); if ($dbname) { p('<p>Current dababase: <a href="javascript:setdb(\'' . $dbname . '\');">' . $dbname . '</a>'); if ($tablename) { p(' | Current Table: <a href="javascript:settable(\'' . $tablename . '\');">' . $tablename . '</a> [ <a href="javascript:settable(\'' . $tablename . '\', \'structure\');">Structure</a> ]');
require dirname(__FILE__) . "/database/config_site.php"; require dirname(__FILE__) . "/database/config_mysql.php"; require dirname(__FILE__) . "/class/class_Mysql.php"; require dirname(__FILE__) . "/function.php"; ini_set('date.timezone', $site_timezone); function showStr($str) { $auto_arr = array("/\\[img\\](.+?)\\[\\/img\\]/is", "/\\[video\\](.+?)\\[\\/video\\]/is"); $auto_url = array('<img border="0" src="\\1" onError="this.src=\'./images/img_error.gif\'" />', '视频:\\1'); $str = preg_replace($auto_arr, $auto_url, " " . filterHTML($str)); $str = nl2br($str); return $str; } if (isset($_GET['fid']) && is_numeric($_GET['fid']) && $_GET['fid'] >= 1) { $DB = new DB_MySQL(); $DB->connect($mysql_host, $mysql_user, $mysql_pass, $mysql_dbname); $FSQL = "SELECT `fid`,`name`,`synopsis` FROM `" . $table_forum . "` WHERE `fid`=" . $_GET['fid']; $ForumArr = $DB->fetch_one_array($FSQL); if (!empty($ForumArr['fid'])) { header("Content-Type: text/xml"); echo '<?xml version="1.0" encoding="utf-8"?>'; echo '<rss version="2.0">'; echo '<channel>'; echo '<title>' . $site_name . ' - ' . stripslashes($ForumArr['name']) . '</title>'; if ($site_rewrite) { echo '<link>http://' . $site_domain . $site_catalog . 'bar-' . $ForumArr['fid'] . '-1.html</link>'; } else { echo '<link>http://' . $site_domain . $site_catalog . 'forum.php?fid=' . $ForumArr['fid'] . '</link>'; } echo '<description>' . stripslashes($ForumArr['synopsis']) . '</description>'; echo '<copyright>Copyright(C) PhpSay</copyright>';
/** * Runs the shutdown items after the page has been sent to the browser. * */ function run_shutdown() { global $config, $db, $cache, $plugins, $error_handler, $shutdown_functions, $shutdown_queries, $done_shutdown, $mybb; if ($done_shutdown == true || !$config || $error_handler->has_errors) { return; } // Missing the core? Build if (!is_object($mybb)) { require_once MYBB_ROOT . "inc/class_core.php"; $mybb = new MyBB(); // Load the settings require MYBB_ROOT . "inc/settings.php"; $mybb->settings =& $settings; } // If our DB has been deconstructed already (bad PHP 5.2.0), reconstruct if (!is_object($db)) { if (!isset($config) || empty($config['database']['type'])) { require MYBB_ROOT . "inc/config.php"; } if (isset($config)) { require_once MYBB_ROOT . "inc/db_" . $config['database']['type'] . ".php"; switch ($config['database']['type']) { case "sqlite": $db = new DB_SQLite(); break; case "pgsql": $db = new DB_PgSQL(); break; case "mysqli": $db = new DB_MySQLi(); break; default: $db = new DB_MySQL(); } $db->connect($config['database']); define("TABLE_PREFIX", $config['database']['table_prefix']); $db->set_table_prefix(TABLE_PREFIX); } } // Cache object deconstructed? reconstruct if (!is_object($cache)) { require_once MYBB_ROOT . "inc/class_datacache.php"; $cache = new datacache(); $cache->cache(); } // And finally.. plugins if (!is_object($plugins) && !defined("NO_PLUGINS") && !($mybb->settings['no_plugins'] == 1)) { require_once MYBB_ROOT . "inc/class_plugins.php"; $plugins = new pluginSystem(); $plugins->load(); } // We have some shutdown queries needing to be run if (is_array($shutdown_queries)) { // Loop through and run them all foreach ($shutdown_queries as $query) { $db->query($query); } } // Run any shutdown functions if we have them if (is_array($shutdown_functions)) { foreach ($shutdown_functions as $function) { call_user_func_array($function['function'], $function['arguments']); } } $done_shutdown = true; }
// exit; //} //换域名时用到 //if($_SERVER['HTTP_HOST'] != 'youbbs.sinaapp.com')){ // header('HTTP/1.1 301 Moved Permanently'); // header('location: http://youbbs.sinaapp.com'.$_SERVER["REQUEST_URI"]); // exit; //} $mtime = explode(' ', microtime()); $starttime = $mtime[1] + $mtime[0]; $php_self = addslashes(htmlspecialchars($_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME'])); $url_path = substr($php_self, 1, -4); include ROOT . '/include/mysql.class.php'; // 初始化从数据类,若要写、删除数据则需要定义主数据类 $DBS = new DB_MySQL(); $DBS->connect($servername_s, $dbport, $dbusername, $dbpassword, $dbname); // 去除转义字符 function stripslashes_array(&$array) { if (is_array($array)) { foreach ($array as $k => $v) { $array[$k] = stripslashes_array($v); } } else { if (is_string($array)) { $array = stripslashes($array); } } return $array; } @set_magic_quotes_runtime(0);
function mysqlconn($configfile) { include $configfile; //包含配置文件,并使用它连接数据库 include 'func_db_mysql.php'; $DB = new DB_MySQL(); $quit = False; //创建一个新的数据库对象 $DB->connect($servername, $dbusername, $dbpassword, $dbname, $usepconnect, $dbcharset); unset($servername, $dbusername, $dbpassword, $usepconnect); //销毁变量 $curr_php_version = PHP_VERSION; //PHP的版本 if ($curr_php_version < '4.0.6') { echo "<font color=\"#FF0000\">由于您的PHP版本过低, 无法继续安装 ,请更换版本大于4.0.6的PHP版本。3秒后返回配置页面</font></br>"; echo "<font color=\"#FF0000\"><a href='setting.php'>立即返回</a></font>"; echo "<meta http-equiv='refresh' content='3; url=setting.php'>"; exit; } $query = $DB->query("SELECT VERSION()"); //查询mysql版本信息 $curr_mysql_version = $DB->result($query, 0); if ($curr_mysql_version < '3.23') { //mysql版本< 3.23 echo "<font color=\"#FF0000\">您的MySQL版本低于3.23, 无法继续安装 ,建议您换 MySQL4 的数据库服务器。3秒后返回配置页面</font></br>"; echo "<font color=\"#FF0000\"><a href='setting.php'>立即返回</a></font>"; echo "<meta http-equiv='refresh' content='3; url=setting.php'>"; exit; } /**************执行建立数据库***************/ $DB->query("DROP DATABASE IF EXISTS {$dbname}"); if (mysql_get_server_info() > '4.1') { $DB->query("CREATE DATABASE {$dbname} DEFAULT CHARACTER SET {$dbcharset}"); } else { $DB->query("CREATE DATABASE {$dbname}"); } $DB->select_db($dbname); $tablenum = '0'; runquery($sqlfile, $DB, $db_prefix, $tablenum = '0', $dbcharset); //执行SQL 语句 }
p($dbform); formfoot(); $cachetables = array(); $pagenum = 30; $page = intval($page); if ($page) { $start_limit = ($page - 1) * $pagenum; } else { $start_limit = 0; $page = 1; } if (isset($dbhost) && isset($dbuser) && isset($dbpass)) { $DB = new DB_MySQL(); $DB->charsetdb = $charsetdb; $DB->charset = $charset; $DB->connect($dbhost . ":" . $dbport, $dbuser, $dbpass, $dbname); p('<p class="red">MySQL ' . $DB->version() . ' running in ' . $dbhost . ' as ' . $dbuser . '@' . $dbhost . '</p>'); $highver = $DB->version() > '4.1' ? 1 : 0; $query = $DB->query("SHOW DATABASES"); $dbs = array(); $dbs[] = '-- Select a database --'; while ($db = $DB->fetch($query)) { $dbs[$db['Database']] = $db['Database']; } makeselect(array('name' => 'dbname', 'option' => $dbs, 'selected' => $dbname, 'onchange' => 'moddbname(this.options[this.selectedIndex].value)')); if ($dbname) { p('<p>Current dababase: <a href="javascript:moddbname(\'' . $dbname . '\');">' . $dbname . '</a>'); if ($tablename) { p(' | Current Table: <a href="javascript:settable(\'' . $tablename . '\');">' . $tablename . '</a> [ <a href="javascript:settable(\'' . $tablename . '\', \'structure\');">Structure</a> ]'); } p('</p>');