/** +---------------------------------------------------------- * 连接数据库方法 +---------------------------------------------------------- * @access public +---------------------------------------------------------- * @throws ThinkExecption +---------------------------------------------------------- */ public function connect($config = '', $linkNum = 0) { if (!isset($this->linkID[$linkNum])) { if (empty($config)) { $config = $this->config; } $this->linkID[$linkNum] = mysqli_connect($config['hostname'], $config['username'], $config['password'], $config['database'], $config['hostport']); if (!$this->linkID[$linkNum]) { throw_exception(mysqli_connect_error()); return false; } if ($this->autoCommit) { mysqli_autocommit($this->linkID[$linkNum], true); } else { mysqli_autocommit($this->linkID[$linkNum], false); } $this->dbVersion = mysqli_get_server_info($this->linkID[$linkNum]); if ($this->dbVersion >= "4.1") { //使用UTF8存取数据库 需要mysql 4.1.0以上支持 mysqli_query($this->linkID[$linkNum], "SET NAMES '" . C('DB_CHARSET') . "'"); } // 标记连接成功 $this->connected = true; //注销数据库安全信息 if (1 != C('DB_DEPLOY_TYPE')) { unset($this->config); } } return $this->linkID[$linkNum]; }
function connect($iteration = 0, $rerunError = null) { if ($iteration > $this->reconnectIterations) { $e = new BrDBConnectionError($rerunError); br()->triggerSticky('db.connectionError', $e); throw $e; } $hostName = br($this->config, 'hostname'); $dataBaseName = br($this->config, 'name'); $userName = br($this->config, 'username'); $password = br($this->config, 'password'); $port = br($this->config, 'port'); try { if ($this->__connection = @mysqli_connect($hostName, $userName, $password, $dataBaseName, $port)) { if (br($this->config, 'charset')) { $this->runQuery('SET NAMES ?', $this->config['charset']); } $this->version = mysqli_get_server_info($this->__connection); $this->triggerSticky('after:connect'); br()->triggerSticky('after:db.connect'); } else { throw new Exception(mysqli_connect_errno() . ': ' . mysqli_connect_error()); } } catch (Exception $e) { if (preg_match('/Unknown database/', $e->getMessage()) || preg_match('/Access denied/', $e->getMessage())) { br()->triggerSticky('db.connectionError', $e); throw new BrDBConnectionError($e->getMessage()); } else { $this->__connection = null; usleep(250000); $this->connect($iteration + 1, $e->getMessage()); } } return $this->__connection; }
/** * Clean orphan objects against linked objects * * @param string $table_link table of linked object for JOIN; deprecated, for backward compatibility * @param string $field_link field of linked object for JOIN; deprecated, for backward compatibility * @param string $field_object field of current object for JOIN; deprecated, for backward compatibility * @return bool true on success */ public function cleanOrphan($table_link = '', $field_link = '', $field_object = '') { if (!empty($table_link)) { $this->handler->table_link = $table_link; } if (!empty($field_link)) { $this->handler->field_link = $field_link; } if (!empty($field_object)) { $this->handler->field_object = $field_object; } if (empty($this->handler->field_object) || empty($this->handler->table_link) || empty($this->handler->field_link)) { trigger_error("The link information is not set for '" . get_class($this->handler) . "' yet.", E_USER_WARNING); return null; } /** * for MySQL 4.1+ */ if (version_compare(mysqli_get_server_info($this->handler->db->conn), '4.1.0', 'ge')) { $sql = "DELETE FROM `{$this->handler->table}`" . " WHERE (`{$this->handler->field_object}` NOT IN ( SELECT DISTINCT `{$this->handler->field_link}` FROM `{$this->handler->table_link}`) )"; } else { // for 4.0+ $sql = "DELETE `{$this->handler->table}` FROM `{$this->handler->table}`" . " LEFT JOIN `{$this->handler->table_link}` AS aa ON `{$this->handler->table}`.`{$this->handler->field_object}` = aa.`{$this->handler->field_link}`" . " WHERE (aa.`{$this->handler->field_link}` IS NULL)"; } if (!($result = $this->handler->db->queryF($sql))) { return false; } return true; }
/** * get MySQL server version * * @param null|XoopsDatabase|mysqli $conn * * @return string */ public function mysql_server_version($conn = null) { if (null === $conn) { $conn = $this->db->conn; } return mysqli_get_server_info($conn); }
public function getAttribute($attribute, &$source = null, $func = 'PDO::getAttribute', &$last_error = null) { if ($source == null) { $source =& $this->driver_options; } switch ($attribute) { case EhrlichAndreas_Pdo_Abstract::ATTR_AUTOCOMMIT: $result = mysqli_query($this->link, 'SELECT @@AUTOCOMMIT', MYSQLI_USE_RESULT); if (!$result) { $this->set_driver_error(null, EhrlichAndreas_Pdo_Abstract::ERRMODE_EXCEPTION, $func); } $row = mysqli_fetch_row($result); mysqli_free_result($result); return intval($row[0]); break; case EhrlichAndreas_Pdo_Abstract::ATTR_CLIENT_VERSION: return mysqli_get_client_info(); break; case EhrlichAndreas_Pdo_Abstract::ATTR_CONNECTION_STATUS: return mysqli_get_host_info($this->link); break; case EhrlichAndreas_Pdo_Abstract::ATTR_SERVER_INFO: return mysqli_stat($this->link); break; case EhrlichAndreas_Pdo_Abstract::ATTR_SERVER_VERSION: return mysqli_get_server_info($this->link); break; default: return parent::getAttribute($attribute, $source, $func, $last_error); break; } }
function dump_properties($mysqli) { printf("\nClass variables:\n"); $variables = array_keys(get_class_vars(get_class($mysqli))); sort($variables); foreach ($variables as $k => $var) { printf("%s = '%s'\n", $var, var_export(@$mysqli->{$var}, true)); } printf("\nObject variables:\n"); $variables = array_keys(get_object_vars($mysqli)); foreach ($variables as $k => $var) { printf("%s = '%s'\n", $var, var_export(@$mysqli->{$var}, true)); } printf("\nMagic, magic properties:\n"); assert(@mysqli_affected_rows($mysqli) === @$mysqli->affected_rows); printf("mysqli->affected_rows = '%s'/%s ('%s'/%s)\n", @$mysqli->affected_rows, gettype(@$mysqli->affected_rows), @mysqli_affected_rows($mysqli), gettype(@mysqli_affected_rows($mysqli))); assert(@mysqli_get_client_info() === @$mysqli->client_info); printf("mysqli->client_info = '%s'/%s ('%s'/%s)\n", @$mysqli->client_info, gettype(@$mysqli->client_info), @mysqli_get_client_info(), gettype(@mysqli_get_client_info())); assert(@mysqli_get_client_version() === @$mysqli->client_version); printf("mysqli->client_version = '%s'/%s ('%s'/%s)\n", @$mysqli->client_version, gettype(@$mysqli->client_version), @mysqli_get_client_version(), gettype(@mysqli_get_client_version())); assert(@mysqli_errno($mysqli) === @$mysqli->errno); printf("mysqli->errno = '%s'/%s ('%s'/%s)\n", @$mysqli->errno, gettype(@$mysqli->errno), @mysqli_errno($mysqli), gettype(@mysqli_errno($mysqli))); assert(@mysqli_error($mysqli) === @$mysqli->error); printf("mysqli->error = '%s'/%s ('%s'/%s)\n", @$mysqli->error, gettype(@$mysqli->error), @mysqli_error($mysqli), gettype(@mysqli_error($mysqli))); assert(@mysqli_field_count($mysqli) === @$mysqli->field_count); printf("mysqli->field_count = '%s'/%s ('%s'/%s)\n", @$mysqli->field_count, gettype(@$mysqli->field_count), @mysqli_field_count($mysqli), gettype(@mysqli_field_count($mysqli))); assert(@mysqli_insert_id($mysqli) === @$mysqli->insert_id); printf("mysqli->insert_id = '%s'/%s ('%s'/%s)\n", @$mysqli->insert_id, gettype(@$mysqli->insert_id), @mysqli_insert_id($mysqli), gettype(@mysqli_insert_id($mysqli))); assert(@mysqli_sqlstate($mysqli) === @$mysqli->sqlstate); printf("mysqli->sqlstate = '%s'/%s ('%s'/%s)\n", @$mysqli->sqlstate, gettype(@$mysqli->sqlstate), @mysqli_sqlstate($mysqli), gettype(@mysqli_sqlstate($mysqli))); assert(@mysqli_get_host_info($mysqli) === @$mysqli->host_info); printf("mysqli->host_info = '%s'/%s ('%s'/%s)\n", @$mysqli->host_info, gettype(@$mysqli->host_info), @mysqli_get_host_info($mysqli), gettype(@mysqli_get_host_info($mysqli))); /* note that the data types are different */ assert(@mysqli_info($mysqli) == @$mysqli->info); printf("mysqli->info = '%s'/%s ('%s'/%s)\n", @$mysqli->info, gettype(@$mysqli->info), @mysqli_info($mysqli), gettype(@mysqli_info($mysqli))); assert(@mysqli_thread_id($mysqli) > @$mysqli->thread_id); assert(gettype(@$mysqli->thread_id) == gettype(@mysqli_thread_id($mysqli))); printf("mysqli->thread_id = '%s'/%s ('%s'/%s)\n", @$mysqli->thread_id, gettype(@$mysqli->thread_id), @mysqli_thread_id($mysqli), gettype(@mysqli_thread_id($mysqli))); assert(@mysqli_get_proto_info($mysqli) === @$mysqli->protocol_version); printf("mysqli->protocol_version = '%s'/%s ('%s'/%s)\n", @$mysqli->protocol_version, gettype(@$mysqli->protocol_version), @mysqli_get_proto_info($mysqli), gettype(@mysqli_get_proto_info($mysqli))); assert(@mysqli_get_server_info($mysqli) === @$mysqli->server_info); printf("mysqli->server_info = '%s'/%s ('%s'/%s)\n", @$mysqli->server_info, gettype(@$mysqli->server_info), @mysqli_get_server_info($mysqli), gettype(@mysqli_get_server_info($mysqli))); assert(@mysqli_get_server_version($mysqli) === @$mysqli->server_version); printf("mysqli->server_version = '%s'/%s ('%s'/%s)\n", @$mysqli->server_version, gettype(@$mysqli->server_version), @mysqli_get_server_version($mysqli), gettype(@mysqli_get_server_version($mysqli))); assert(@mysqli_warning_count($mysqli) === @$mysqli->warning_count); printf("mysqli->warning_count = '%s'/%s ('%s'/%s)\n", @$mysqli->warning_count, gettype(@$mysqli->warning_count), @mysqli_warning_count($mysqli), gettype(@mysqli_warning_count($mysqli))); printf("\nAccess to undefined properties:\n"); printf("mysqli->unknown = '%s'\n", @$mysqli->unknown); @($mysqli->unknown = 13); printf("setting mysqli->unknown, @mysqli_unknown = '%s'\n", @$mysqli->unknown); $unknown = 'friday'; @($mysqli->unknown = $unknown); printf("setting mysqli->unknown, @mysqli_unknown = '%s'\n", @$mysqli->unknown); printf("\nAccess hidden properties for MYSLQI_STATUS_INITIALIZED (TODO documentation):\n"); assert(@mysqli_connect_error() === @$mysqli->connect_error); printf("mysqli->connect_error = '%s'/%s ('%s'/%s)\n", @$mysqli->connect_error, gettype(@$mysqli->connect_error), @mysqli_connect_error(), gettype(@mysqli_connect_error())); assert(@mysqli_connect_errno() === @$mysqli->connect_errno); printf("mysqli->connect_errno = '%s'/%s ('%s'/%s)\n", @$mysqli->connect_errno, gettype(@$mysqli->connect_errno), @mysqli_connect_errno(), gettype(@mysqli_connect_errno())); }
public function getList() { if (!$this->_list) { $server_software = !empty($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : JText::_('n/a'); $rows = array(array('setting' => JText::_('PHP Built On'), 'value' => php_uname()), array('setting' => JText::_('Database Version'), 'value' => mysqli_get_server_info($this->getService('koowa:database.adapter.mysqli')->getConnection())), array('setting' => JText::_('Database Collation'), 'value' => $this->getService('com://admin/extensions.database.table.plugins')->getSchema()->collation), array('setting' => JText::_('PHP Version'), 'value' => phpversion()), array('setting' => JText::_('Web Server'), 'value' => $server_software), array('setting' => JText::_('WebServer to PHP Interface'), 'value' => php_sapi_name()), array('setting' => JText::_('Nooku Server Version'), 'value' => Koowa::getVersion()), array('setting' => JText::_('User Agent'), 'value' => $_SERVER['HTTP_USER_AGENT'], ENT_QUOTES)); $this->_list = $this->getService('com://admin/info.database.rowset.system')->addData($rows, false); } return $this->_list; }
private function show_info() { $total_space = round(@disk_total_space(".") / (1024 * 1024)); $free_space = round(@disk_free_space(".") / (1024 * 1024)); $already_used = round($total_space - $free_space); $already_used_percent = round(($total_space - $free_space) / $total_space * 100); $server_info = array('os' => PHP_OS, 'server_software' => $_SERVER["SERVER_SOFTWARE"], 'php' => php_sapi_name(), 'mysqli' => mysqli_get_server_info($this->model->getDb()), 'canon_version' => 1.0 . " [<a href='http://phpgoto.com' target='_blank'>访问官网</a>]", 'upload' => ini_get('upload_max_filesize'), 'total_space' => $total_space, 'free_space' => $free_space, 'already_used' => $already_used, 'already_used_percent' => $already_used_percent); //dump($server_info); return $server_info; }
function _db_set_charset($charset, $collation) { if (!isset($this->use_set_names)) { $this->use_set_names = version_compare(mysqli_get_server_info($this->conn_id), '5.0.7', '>=') ? FALSE : TRUE; } if ($this->use_set_names === TRUE) { return @mysqli_query($this->conn_id, "SET NAMES '" . $this->escape_str($charset) . "' COLLATE '" . $this->escape_str($collation) . "'"); } else { return @mysqli_set_charset($this->conn_id, $charset); } }
protected final function isServerSupportingSavePoints() { if ($this->supportsSavePoints === null) { $version = mysqli_get_server_info($this->link); if (version_compare($version, '5.0.3') >= 0) { $this->supportsSavePoints = true; } else { $this->supportsSavePoints = false; } } return $this->supportsSavePoints; }
function versionMysql() { $test = is_null($___mysqli_res = mysqli_get_server_info($GLOBALS["mysqli"])) ? false : $___mysqli_res; // On regarde si c'est une version 4 ou 5 $version = mb_substr($test, 0, 1); if ($version == 4 or $version == 5) { $retour = '<span style="color: green;">' . (is_null($___mysqli_res = mysqli_get_server_info($GLOBALS["mysqli"])) ? false : $___mysqli_res) . '</span>'; } else { $retour = '<span style="color: red;">' . (is_null($___mysqli_res = mysqli_get_server_info($GLOBALS["mysqli"])) ? false : $___mysqli_res) . '(version ancienne !)</span>'; } return $retour; }
private function connect() { $this->id = mysqli_connect($this->config['location'], $this->config['user'], $this->config['pass'], $this->config['name']); if (!$this->id) { if ($this->config['show_error'] == 1) { $this->display_error(mysqli_connect_error(), '1', 'connect'); } else { return false; } } $this->mysql_version = mysqli_get_server_info($this->id); mysqli_query($this->id, "SET NAMES '" . $this->collate . "'"); }
function serverVers() { // cache for faster execution: if (is_array($this->_drvSrvVersArr)) { return $this->_drvSrvVersArr; } $orig = @mysqli_get_server_info($this->_conn); $vstr = $this->_findVers($orig); $vint = @mysqli_get_server_version($this->_conn); $vArr = array('orig' => $orig, 'vstr' => $vstr, 'vint' => $vint); $this->_drvSrvVersArr = $vArr; return $vArr; }
/** * get MySQL server version * * In some cases mysql_get_client_info is required instead * * @param null $conn * * @return string */ function mod_getMysqlVersion($conn = null) { global $xoopsDB; static $mysql_version; if (isset($mysql_version)) { return $mysql_version; } if (null === $conn) { $conn = $xoopsDB->conn; } $mysql_version = mysqli_get_server_info($conn); return $mysql_version; }
function vbseodb_connect($server, $user, $password, $usepconnect, $tableprefix = '', $database, $port) { global $vbulletin, $DB_site, $config; if (!defined('TABLE_PREFIX')) { define('TABLE_PREFIX', $tableprefix); } if (0 == $this->link_id) { $this->mysqli = $config['Database']['dbtype'] == 'mysqli'; if (is_object($vbulletin) && isset($vbulletin->db) && (isset($vbulletin->db->connection_slave) && ($dlnk = $vbulletin->db->connection_slave) || isset($vbulletin->db->connection_master) && ($dlnk = $vbulletin->db->connection_master)) && (@is_object($dlnk) ? @mysqli_get_server_info($dlnk) : @mysql_get_server_info($dlnk))) { $this->link_id = $dlnk; } else { if (isset($DB_site) && $DB_site->link_id) { $this->link_id = $DB_site->link_id; } else { $this->own_link = 1; if ($usepconnect == 1) { $this->link_id = @mysql_pconnect($server . ($port && $port != 3306 ? ':' . $port : ''), $user, $password); } else { if ($this->mysqli) { $this->link_id = mysqli_init(); @mysqli_real_connect($this->link_id, $server, $user, $password, $database, $port); } else { $this->link_id = @mysql_connect($server . ($port && $port != 3306 ? ':' . $port : ''), $user, $password); } } } } if (!$this->link_id) { return false; } $this->mysqli = @is_object($this->link_id); if ($this->mysqli) { $this->funcs = array('get_server_info' => 'mysqli_get_server_info', 'select_db' => 'mysqli_select_db', 'query' => 'mysqli_query', 'affected_rows' => 'mysqli_affected_rows', 'num_rows' => 'mysqli_num_rows', 'free_result' => 'mysqli_free_result', 'fetch_array' => 'mysqli_fetch_array', 'fetch_assoc' => 'mysqli_fetch_assoc', 'close' => 'mysqli_close'); } else { $this->funcs = array('get_server_info' => 'mysql_get_server_info', 'select_db' => 'mysql_select_db', 'query' => 'mysql_query', 'affected_rows' => 'mysql_affected_rows', 'num_rows' => 'mysql_num_rows', 'free_result' => 'mysql_free_result', 'fetch_array' => 'mysql_fetch_array', 'fetch_assoc' => 'mysql_fetch_assoc', 'close' => 'mysql_close'); $this->vbseodb_select_db($database); } if (isset($config['Mysqli']['charset']) && ($charset = $config['Mysqli']['charset'])) { if ($this->mysqli && function_exists('mysqli_set_charset')) { mysqli_set_charset($this->link_id, $charset); } else { $this->vbseodb_query("SET NAMES {$charset}"); } } $this->mysql_version = function_exists($this->funcs['get_server_info']) ? $this->funcs['get_server_info']($this->link_id) : ''; return true; } }
function xtc_db_connect_installer($server, $username, $password, $database, $link = 'db_link') { global ${$link}, $db_error; $db_error = false; if (!$server) { $db_error = 'No Server selected.'; return false; } ${$link} = @mysqli_connect($server, $username, $password, $database) or $db_error = mysqli_error(${$link}); //vr - 2010-01-01 - Disable "STRICT" mode for MySQL 5! if (version_compare(@mysqli_get_server_info(${$link}), '5.0.0', '>=')) { @mysqli_query(${$link}, "SET SESSION sql_mode=''"); } mysqli_set_charset(${$link}, 'utf8'); return ${$link}; }
public static function getMySQLInfo() { if (isset(self::$_aMySQLInfo)) { return self::$_aMySQLInfo; } global $wpdb; $_aOutput = array('Version' => isset($wpdb->use_mysqli) && $wpdb->use_mysqli ? @mysqli_get_server_info($wpdb->dbh) : @mysql_get_server_info()); foreach ((array) $wpdb->get_results("SHOW VARIABLES", ARRAY_A) as $_iIndex => $_aItem) { $_aItem = array_values($_aItem); $_sKey = array_shift($_aItem); $_sValue = array_shift($_aItem); $_aOutput[$_sKey] = $_sValue; } self::$_aMySQLInfo = $_aOutput; return self::$_aMySQLInfo; }
/** * Fetch Anonymous Server Data * * @access public * @return array */ function fetch_anon_server_data() { $CI =& get_instance(); $CI->db->select('site_system_preferences'); $query = $CI->db->get_where('sites', array('site_id' => 1)); $site_url = ''; $path_info_support = 'n'; if ($query->num_rows() > 0) { $prefs = unserialize(base64_decode($query->row('site_system_preferences'))); $site_url = $prefs['site_url']; $path_info_support = $prefs['force_query_string'] == 'n' ? 'y' : 'n'; } // Get a list of add-ons in their third_party folder $CI->load->helper('directory'); $mysql_info = $CI->db->dbdriver == 'mysqli' ? mysqli_get_server_info($CI->db->conn_id) : mysql_get_server_info(); return array('anon_id' => md5($site_url), 'os' => preg_replace("/.*?\\((.*?)\\).*/", '\\1', $_SERVER['SERVER_SOFTWARE']), 'server_software' => preg_replace("/(.*?)\\(.*/", '\\1', $_SERVER['SERVER_SOFTWARE']), 'php_version' => phpversion(), 'php_extensions' => json_encode(get_loaded_extensions()), 'mysql_version' => preg_replace("/(.*?)\\-.*/", "\\1", $mysql_info), 'path_info_support' => $path_info_support, 'addons' => json_encode(directory_map(PATH_THIRD, 1)), 'forums' => $CI->config->item('forum_is_installed') == "y" ? 'y' : 'n', 'msm' => $CI->config->item('multiple_sites_enabled') == "y" ? 'y' : 'n'); }
function connect() { $this->conn = mysqli_connect($this->host, $this->user, $this->password); mysqli_select_db($this->conn, $this->dbname); if (function_exists('mysqli_set_charset')) { mysqli_set_charset($this->conn, $this->connection_charset); } $this->dbVersion = 3.23; // assume version 3.23 if (function_exists("mysqli_get_server_info")) { $ver = mysqli_get_server_info($this->conn); $this->dbMODx = version_compare($ver, "4.0.2"); $this->dbVersion = (double) $ver; // Typecasting (float) instead of floatval() [PHP < 4.2] } mysqli_query($this->conn, "{$this->connection_method} {$this->connection_charset}"); }
function connect() { if (defined('USE_PCONNECT') && USE_PCONNECT == 'true') { $connect_function = 'mysqli_pconnect'; } else { $connect_function = 'mysqli_connect'; } if ($this->link = @$connect_function($this->server, $this->username, $this->password)) { $this->setConnected(true); if (version_compare(mysqli_get_server_info($this->link), '5.0.2') >= 0) { $this->simpleQuery('set session sql_mode="STRICT_ALL_TABLES"'); } return true; } else { $this->setError(mysqli_connect_error(), mysqli_connect_errno()); return false; } }
/** * 连接数据库 * @param type $hostUrl * @param type $username * @param type $pwd * @param type $dbname * @param type $db_language * @return boolean */ public static function Open($hostUrl, $username, $pwd, $dbname, $db_language = 'UTF8') { if (DB::$isOpen) { return TRUE; } //连接数据库 DB::$linkID = 0; DB::$result["me"] = 0; $info = parse_url($hostUrl); $dbhost = ''; if (isset($info['host'])) { $info['host']; } else { $dbhost = isset($info['path']) ? $info['path'] : $hostUrl; } if (!isset($info['port'])) { $dbport = 3306; } else { $dbport = $info['port']; } DB::$linkID = mysqli_init(); mysqli_real_connect(DB::$linkID, $dbhost, $username, $pwd, false, $dbport); if (mysqli_errno(DB::$linkID) != 0) { DB::DisplayError('ERROR: DB CONNECTING :' . mysqli_errno(DB::$linkID)); } //处理错误,成功连接则选择数据库 if (!DB::$linkID) { DB::DisplayError('ERROR: DB CONNECTING'); return false; } DB::$isOpen = TRUE; $serverinfo = mysqli_get_server_info(DB::$linkID); if ($serverinfo > '4.1') { mysqli_query(DB::$linkID, "SET character_set_connection={$db_language},character_set_results={$db_language},character_set_client=binary"); } if ($serverinfo > '5.0') { mysqli_query(DB::$linkID, "SET sql_mode=''"); } if ($dbname && !@mysqli_select_db(DB::$linkID, $dbname)) { DB::DisplayError('DATABASE CAN NOT BE USE'); return false; } return TRUE; }
/** * Connects to the database using options in the given configuration array. * * @return boolean True if the database could be connected, else false */ function connect() { $config = $this->config; $this->connected = false; if (is_numeric($config['port'])) { $config['socket'] = null; } else { $config['socket'] = $config['port']; $config['port'] = null; } $this->connection = mysqli_connect($config['host'], $config['login'], $config['password'], $config['database'], $config['port'], $config['socket']); if ($this->connection !== false) { $this->connected = true; } $this->_useAlias = (bool) version_compare(mysqli_get_server_info($this->connection), "4.1", ">="); if (!empty($config['encoding'])) { $this->setEncoding($config['encoding']); } return $this->connected; }
public function getMysqlVersion() { $version = array(); $output = ''; if (mysqli_get_server_info($this->conn)) { $output = mysqli_get_server_info($this->conn); } else { $output = shell_exec('mysql -V'); } if ($output) { if (strpos($output, 'MariaDB') !== false) { $version["db"] = 'MariaDB'; } else { $version["db"] = 'mysql'; preg_match('@[0-9]+\\.[0-9]+\\.[0-9]+@', $output, $ver); $version["ver"] = $ver[0]; } } return $version; }
function xtc_db_connect($server = DB_SERVER, $username = DB_SERVER_USERNAME, $password = DB_SERVER_PASSWORD, $database = DB_DATABASE, $link = 'db_link') { global ${$link}; if (!function_exists('mysqli_connect')) { die('Call to undefined function: mysqli_connect(). Please install the MySQL Connector for PHP'); } if (USE_PCONNECT == 'true') { ${$link} = @mysqli_connect($server, $username, $password, $database); } else { ${$link} = @mysqli_connect($server, $username, $password, $database); } //vr - 2010-01-01 - Disable "STRICT" mode for MySQL 5! if (version_compare(@mysqli_get_server_info(), '5.0.0', '>=')) { @mysqli_query("SET SESSION sql_mode=''"); } if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } mysqli_set_charset(${$link}, 'utf8'); return ${$link}; }
function connect($db_user, $db_pass, $db_name, $db_location = 'localhost', $show_error = 1) { $db_location = explode(":", $db_location); if (isset($db_location[1])) { $this->db_id = @mysqli_connect($db_location[0], $db_user, $db_pass, $db_name, $db_location[1]); } else { $this->db_id = @mysqli_connect($db_location[0], $db_user, $db_pass, $db_name); } if (!$this->db_id) { if ($show_error == 1) { $this->display_error(mysqli_connect_error(), '1'); } else { return false; } } $this->mysql_version = mysqli_get_server_info($this->db_id); if (!defined('COLLATE')) { define("COLLATE", "cp1251"); } mysqli_query($this->db_id, "SET NAMES '" . COLLATE . "'"); return true; }
function __construct($username, $password, $hostname, $database, $new = false) { if (strstr($hostname, ':')) { list($host, $port) = @explode(":", $hostname); } if ($this->connection = @mysqli_connect($host, $username, $password, $database, $port)) { $this->havedb = true; } //fix to support utf8, warning it only works from a certain mySQL version on //needed on mySQL servers that don't have the default connection encoding setting to utf8 //As we do not have any setting for ISAM or InnoDB tables yet, i set the minimum specs // for using this feature to 4.1.2, although isam tables got the support for utf8 already in 4.1 //anything else would result in an inconsistent user experience //TODO: determine how to handle encoding on postgres list($major, $minor, $micro) = sscanf(@mysqli_get_server_info($this->connection), "%d.%d.%d-%s"); if (defined('DB_ENCODING')) { //SET NAMES is possible since version 4.1 if ($major > 4 or $major == 4 and $minor >= 1) { @mysqli_query($this->connection, "SET NAMES " . DB_ENCODING); } } $this->prefix = DB_TABLE_PREFIX . '_'; }
function my_mysql_get_server_info($conn = FALSE) { if (myext() == 'mysqli') { return @mysqli_get_server_info($conn); } else { return $conn ? @mysql_get_server_info($conn) : @mysql_get_server_info(); } }
/** * Outputs diagnostic info for debugging. * * Outputs useful diagnostic info text at the Diagnostic Info & Error Log * section under the Help tab so the information can be viewed or * downloaded and shared for debugging. * * If you would like to add additional diagnostic information use the * `wpmdb_diagnostic_info` action hook (see {@link https://developer.wordpress.org/reference/functions/add_action/}). * * <code> * add_action( 'wpmdb_diagnostic_info', 'my_diagnostic_info' ) { * echo "Additional Diagnostic Info: \r\n"; * echo "...\r\n"; * } * </code> * * @return void */ function output_diagnostic_info() { global $wpdb; $table_prefix = $wpdb->base_prefix; echo 'site_url(): '; echo esc_html(site_url()); echo "\r\n"; echo 'home_url(): '; echo esc_html(home_url()); echo "\r\n"; echo 'Database Name: '; echo esc_html($wpdb->dbname); echo "\r\n"; echo 'Table Prefix: '; echo esc_html($table_prefix); echo "\r\n"; echo 'WordPress: '; echo bloginfo('version'); if (is_multisite()) { echo ' Multisite'; } echo "\r\n"; echo 'Web Server: '; echo esc_html(!empty($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : ''); echo "\r\n"; echo 'PHP: '; if (function_exists('phpversion')) { echo esc_html(phpversion()); } echo "\r\n"; echo 'MySQL: '; echo esc_html(empty($wpdb->use_mysqli) ? mysql_get_server_info() : mysqli_get_server_info($wpdb->dbh)); echo "\r\n"; echo 'ext/mysqli: '; echo empty($wpdb->use_mysqli) ? 'no' : 'yes'; echo "\r\n"; echo 'WP Memory Limit: '; echo esc_html(WP_MEMORY_LIMIT); echo "\r\n"; echo 'Blocked External HTTP Requests: '; if (!defined('WP_HTTP_BLOCK_EXTERNAL') || !WP_HTTP_BLOCK_EXTERNAL) { echo 'None'; } else { $accessible_hosts = defined('WP_ACCESSIBLE_HOSTS') ? WP_ACCESSIBLE_HOSTS : ''; if (empty($accessible_hosts)) { echo 'ALL'; } else { echo 'Partially (Accessible Hosts: ' . esc_html($accessible_hosts) . ')'; } } echo "\r\n"; echo 'WPMDB Bottleneck: '; echo esc_html(size_format($this->get_bottleneck())); echo "\r\n"; echo 'WP Locale: '; echo esc_html(get_locale()); echo "\r\n"; echo 'DB Charset: '; echo esc_html(DB_CHARSET); echo "\r\n"; if (function_exists('ini_get') && ($suhosin_limit = ini_get('suhosin.post.max_value_length'))) { echo 'Suhosin Post Max Value Length: '; echo esc_html(is_numeric($suhosin_limit) ? size_format($suhosin_limit) : $suhosin_limit); echo "\r\n"; } if (function_exists('ini_get') && ($suhosin_limit = ini_get('suhosin.request.max_value_length'))) { echo 'Suhosin Request Max Value Length: '; echo esc_html(is_numeric($suhosin_limit) ? size_format($suhosin_limit) : $suhosin_limit); echo "\r\n"; } echo 'Debug Mode: '; echo esc_html(defined('WP_DEBUG') && WP_DEBUG ? 'Yes' : 'No'); echo "\r\n"; echo 'WP Max Upload Size: '; echo esc_html(size_format(wp_max_upload_size())); echo "\r\n"; echo 'PHP Post Max Size: '; echo esc_html(size_format($this->get_post_max_size())); echo "\r\n"; echo 'PHP Time Limit: '; if (function_exists('ini_get')) { echo esc_html(ini_get('max_execution_time')); } echo "\r\n"; echo 'PHP Error Log: '; if (function_exists('ini_get')) { echo esc_html(ini_get('error_log')); } echo "\r\n"; echo 'fsockopen: '; if (function_exists('fsockopen')) { echo 'Enabled'; } else { echo 'Disabled'; } echo "\r\n"; echo 'OpenSSL: '; if ($this->open_ssl_enabled()) { echo esc_html(OPENSSL_VERSION_TEXT); } else { echo 'Disabled'; } echo "\r\n"; echo 'cURL: '; if (function_exists('curl_init')) { echo 'Enabled'; } else { echo 'Disabled'; } echo "\r\n"; echo 'Enable SSL verification setting: '; if (1 == $this->settings['verify_ssl']) { echo 'Yes'; } else { echo 'No'; } echo "\r\n"; echo 'Compatibility Mode: '; if (isset($GLOBALS['wpmdb_compatibility'])) { echo 'Yes'; } else { echo 'No'; } echo "\r\n"; echo 'Delay Between Requests: '; $delay_between_requests = $this->settings['delay_between_requests']; $delay_between_requests = $delay_between_requests > 0 ? $delay_between_requests / 1000 : $delay_between_requests; echo esc_html($delay_between_requests) . ' s'; echo "\r\n\r\n"; do_action('wpmdb_diagnostic_info'); if (has_action('wpmdb_diagnostic_info')) { echo "\r\n"; } $theme_info = wp_get_theme(); echo "Active Theme Name: " . esc_html($theme_info->Name) . "\r\n"; echo "Active Theme Folder: " . esc_html(basename($theme_info->get_stylesheet_directory())) . "\r\n"; if ($theme_info->get('Template')) { echo "Parent Theme Folder: " . esc_html($theme_info->get('Template')) . "\r\n"; } if (!file_exists($theme_info->get_stylesheet_directory())) { echo "WARNING: Active Theme Folder Not Found\r\n"; } echo "\r\n"; echo "Active Plugins:\r\n"; if (isset($GLOBALS['wpmdb_compatibility'])) { remove_filter('option_active_plugins', 'wpmdbc_exclude_plugins'); remove_filter('site_option_active_sitewide_plugins', 'wpmdbc_exclude_site_plugins'); $blacklist = array_flip((array) $this->settings['blacklist_plugins']); } else { $blacklist = array(); } $active_plugins = (array) get_option('active_plugins', array()); if (is_multisite()) { $network_active_plugins = wp_get_active_network_plugins(); $active_plugins = array_map(array($this, 'remove_wp_plugin_dir'), $network_active_plugins); } foreach ($active_plugins as $plugin) { $suffix = isset($blacklist[$plugin]) ? '*' : ''; $this->print_plugin_details(WP_PLUGIN_DIR . '/' . $plugin, $suffix); } if (isset($GLOBALS['wpmdb_compatibility'])) { add_filter('option_active_plugins', 'wpmdbc_exclude_plugins'); add_filter('site_option_active_sitewide_plugins', 'wpmdbc_exclude_site_plugins'); } $mu_plugins = wp_get_mu_plugins(); if ($mu_plugins) { echo "\r\n"; echo "Must-use Plugins:\r\n"; foreach ($mu_plugins as $mu_plugin) { $this->print_plugin_details($mu_plugin); } } }
/** * Build db-specific report * @access private */ function _sql_report($mode, $query = '') { static $test_prof; // current detection method, might just switch to see the existance of INFORMATION_SCHEMA.PROFILING if ($test_prof === null) { $test_prof = false; if (strpos(mysqli_get_server_info($this->db_connect_id), 'community') !== false) { $ver = mysqli_get_server_version($this->db_connect_id); if ($ver >= 50037 && $ver < 50100) { $test_prof = true; } } } switch ($mode) { case 'start': $explain_query = $query; if (preg_match('/UPDATE ([a-z0-9_]+).*?WHERE(.*)/s', $query, $m)) { $explain_query = 'SELECT * FROM ' . $m[1] . ' WHERE ' . $m[2]; } else { if (preg_match('/DELETE FROM ([a-z0-9_]+).*?WHERE(.*)/s', $query, $m)) { $explain_query = 'SELECT * FROM ' . $m[1] . ' WHERE ' . $m[2]; } } if (preg_match('/^SELECT/', $explain_query)) { $html_table = false; // begin profiling if ($test_prof) { @mysqli_query($this->db_connect_id, 'SET profiling = 1;'); } if ($result = @mysqli_query($this->db_connect_id, "EXPLAIN {$explain_query}")) { while ($row = @mysqli_fetch_assoc($result)) { $html_table = $this->sql_report('add_select_row', $query, $html_table, $row); } } @mysqli_free_result($result); if ($html_table) { $this->html_hold .= '</table>'; } if ($test_prof) { $html_table = false; // get the last profile if ($result = @mysqli_query($this->db_connect_id, 'SHOW PROFILE ALL;')) { $this->html_hold .= '<br />'; while ($row = @mysqli_fetch_assoc($result)) { // make <unknown> HTML safe if (!empty($row['Source_function'])) { $row['Source_function'] = str_replace(array('<', '>'), array('<', '>'), $row['Source_function']); } // remove unsupported features foreach ($row as $key => $val) { if ($val === null) { unset($row[$key]); } } $html_table = $this->sql_report('add_select_row', $query, $html_table, $row); } } @mysqli_free_result($result); if ($html_table) { $this->html_hold .= '</table>'; } @mysqli_query($this->db_connect_id, 'SET profiling = 0;'); } } break; case 'fromcache': $endtime = explode(' ', microtime()); $endtime = $endtime[0] + $endtime[1]; $result = @mysqli_query($this->db_connect_id, $query); while ($void = @mysqli_fetch_assoc($result)) { // Take the time spent on parsing rows into account } @mysqli_free_result($result); $splittime = explode(' ', microtime()); $splittime = $splittime[0] + $splittime[1]; $this->sql_report('record_fromcache', $query, $endtime, $splittime); break; } }
private function _checkMySQLVersion($sMySQLVersion) { global $wpdb; $_sInstalledMySQLVersion = isset($wpdb->use_mysqli) && $wpdb->use_mysqli ? @mysqli_get_server_info($wpdb->dbh) : @mysql_get_server_info(); return $_sInstalledMySQLVersion ? version_compare($_sInstalledMySQLVersion, $sMySQLVersion, ">=") : true; }