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())); }
/** * A string that represents the MySQL client library version. * * @param DB $db * * @return string */ public static function get_mysql_client_version(DB $db) { static $_mysqli_client_version = null; if ($_mysqli_client_version === null) { $_mysqli_client_version = \mysqli_get_client_version($db->getLink()); } return $_mysqli_client_version; }
public function getMySQLVersion() { $version = mysqli_get_client_version(); $mv = floor($version / 10000); $version = $version - $mv * 10000; $sv = floor($version / 100); $bv = $version - $sv * 100; return $mv . "." . $sv . "." . $bv; //return mysqli_get_client_version(); }
function checkMysqlClientVersion() { $mysqli = new mysqli("127.0.0.1", "bober", "YaB2sQR346VbNcee", "bober", 3307); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit; } return mysqli_get_client_version($mysqli); }
public function check() { $data = array(); $status = 1; //输出基本配置信息 $data['env']['操作系统'] = array('need' => '不限制', 'best' => '类Unix', 'current' => PHP_OS); $data['env']['PHP'] = array('need' => '5.2', 'best' => '5.4 or new', 'current' => PHP_VERSION); if (function_exists('mysqli_get_client_version')) { $current = 'mysqli:' . mysqli_get_client_version(); } elseif (function_exists('mysql_get_client_info')) { $current = 'mysql:' . mysql_get_client_info(); } else { $current = '未安装'; $status = 0; } $data['env']['数据库'] = array('need' => '与php版本对应', 'best' => '与php版本对应', 'current' => $current); $gd_info = array(); if (function_exists('gd_info')) { $gd_info = gd_info(); } else { $status = 0; } $data['env']['GD库'] = array('need' => '1.0', 'best' => '2.0', 'current' => isset($gd_info['GD Version']) ? $gd_info['GD Version'] : '未安装'); $curl_version = array(); if (function_exists('curl_version')) { $curl_version = curl_version(); } else { $status = 0; } $data['env']['CURL扩展'] = array('need' => '与php版本对应', 'best' => '与php版本对应', 'current' => isset($curl_version['version']) ? $curl_version['version'] : '未安装'); if (class_exists('ZipArchive')) { $current = '已安装'; } else { $current = '未安装'; $status = 0; } $data['env']['ZIP扩展'] = array('need' => '与php版本对应', 'best' => '与php版本对应', 'current' => $current); //检查文件是否可写 $check_write_file = array(); $check_write_file = array('api/application/config/database.php' => APPPATH . 'config/database.php', 'api/application/cache' => APPPATH . 'cache', 'api/application/logs' => APPPATH . 'logs', 'api/resources' => dirname(APPPATH) . '/resources'); foreach ($check_write_file as $item => $file) { if (is_writable($file)) { $is_writable = 1; } else { $is_writable = 0; $status = 0; } $data['writeable'][$item] = $is_writable; } $data['allow_next'] = $status; echo $this->to_api_message(1, 'check_env', $data); }
function dbcheck_mysqli() { global $language, $lang_update_php; if (!isset($language)) { $language = $lang_update_php; } if (!function_exists('mysqli_connect')) { return $language['not_available']; } if (mysqli_get_client_version() < 40000) { return $language['version_too_old']; } return true; }
$dbList = null; $dbTests = array('mysql_connect', 'mysqli_connect', 'pg_connect', 'mssql_connect', 'sqlite_open'); foreach ($dbTests as $test) { if (function_exists($test) && is_callable($test)) { $db = explode('_', $test); switch ($db[0]) { default: $dbList[] = $db[0]; break; case 'mysql': $dbList[] = $db[0] . ' (Server: ' . mysql_get_server_info() . ')'; break; case 'mysqli': include cmsROOT . 'cache/config.php'; $mysqli = new mysqli($config['db']['host'], $config['db']['username'], $config['db']['password'], $config['db']['database']); $dbList[] = $db[0] . ' (Server: ' . mysqli_get_server_version($mysqli) . ', Client: ' . mysqli_get_client_version() . ')'; $mysqli->close(); unset($mysqli, $config['db']); break; case 'sqlite': $dbList[] = $db[0] . ' (Server: ' . sqlite_libversion() . ')'; break; case 'pg': $dbList[] = 'postgre (Server: ' . pg_version() . ')'; break; } } } if (class_exists('SQLite3', false) && is_callable(array('SQLite3', 'open'))) { $ver = SQLite3::version(); $dbList[] = 'SQLite3 (Server: ' . $ver['versionString'] . ')';
/** * Renders stage 2: either config details panel (on success) or database details * error message (on fail). */ function printConfig() { $_SESSION['ddb'] = ps('ddb'); $_SESSION['duser'] = ps('duser'); $_SESSION['dpass'] = ps('dpass'); $_SESSION['dhost'] = ps('dhost'); $_SESSION['dprefix'] = ps('dprefix'); $_SESSION['siteurl'] = ps('siteurl'); $GLOBALS['textarray'] = setup_load_lang($_SESSION['lang']); global $txpcfg; echo txp_setup_progress_meter(2) . n . '<div class="txp-setup">'; if (!isset($txpcfg['db'])) { @(include txpath . '/config.php'); } if (!empty($txpcfg['db'])) { echo graf(span(null, array('class' => 'ui-icon ui-icon-alert')) . ' ' . setup_gTxt('already_installed', array('{txpath}' => txpath)), array('class' => 'alert-block warning')) . setup_back_button(__FUNCTION__) . n . '</div>'; exit; } // TODO: @see http://forum.textpattern.com/viewtopic.php?pid=263205#p263205 // if ('' === $_SESSION['dhost'] || '' === $_SESSION['duser'] || '' === $_SESSION['ddb']) { // echo graf( // span(null, array('class' => 'ui-icon ui-icon-alert')).' '. // setup_gTxt('missing_db_details'), // array('class' => 'alert-block warning') // ). // n.setup_back_button(__FUNCTION__). // n.'</div>'; // // exit; // } echo hed(setup_gTxt("checking_database"), 2); if (strpos($_SESSION['dhost'], ':') === false) { $dhost = $_SESSION['dhost']; $dport = ini_get("mysqli.default_port"); } else { list($dhost, $dport) = explode(':', $_SESSION['dhost'], 2); $dport = intval($dport); } $dsocket = ini_get("mysqli.default_socket"); $mylink = mysqli_init(); if (@mysqli_real_connect($mylink, $dhost, $_SESSION['duser'], $_SESSION['dpass'], '', $dport, $dsocket)) { $_SESSION['dclient_flags'] = 0; } elseif (@mysqli_real_connect($mylink, $dhost, $_SESSION['duser'], $_SESSION['dpass'], '', $dport, $dsocket, MYSQLI_CLIENT_SSL)) { $_SESSION['dclient_flags'] = 'MYSQLI_CLIENT_SSL'; } else { echo graf(span(null, array('class' => 'ui-icon ui-icon-closethick')) . ' ' . setup_gTxt('db_cant_connect'), array('class' => 'alert-block error')) . setup_back_button(__FUNCTION__) . n . '</div>'; exit; } echo graf(span(null, array('class' => 'ui-icon ui-icon-check')) . ' ' . setup_gTxt('db_connected'), array('class' => 'alert-block success')); if (!($_SESSION['dprefix'] == '' || preg_match('#^[a-zA-Z_][a-zA-Z0-9_]*$#', $_SESSION['dprefix']))) { echo graf(span(null, array('class' => 'ui-icon ui-icon-closethick')) . ' ' . setup_gTxt('prefix_bad_characters', array('{dbprefix}' => strong(txpspecialchars($_SESSION['dprefix']))), 'raw'), array('class' => 'alert-block error')) . setup_back_button(__FUNCTION__) . n . '</div>'; exit; } if (!($mydb = mysqli_select_db($mylink, $_SESSION['ddb']))) { echo graf(span(null, array('class' => 'ui-icon ui-icon-closethick')) . ' ' . setup_gTxt('db_doesnt_exist', array('{dbname}' => strong(txpspecialchars($_SESSION['ddb']))), 'raw'), array('class' => 'alert-block error')) . setup_back_button(__FUNCTION__) . n . '</div>'; exit; } $tables_exist = mysqli_query($mylink, "DESCRIBE `" . $_SESSION['dprefix'] . "textpattern`"); if ($tables_exist) { echo graf(span(null, array('class' => 'ui-icon ui-icon-closethick')) . ' ' . setup_gTxt('tables_exist', array('{dbname}' => strong(txpspecialchars($_SESSION['ddb']))), 'raw'), array('class' => 'alert-block error')) . setup_back_button(__FUNCTION__) . n . '</div>'; exit; } // On MySQL 5.5.3+ use real UTF-8 tables, if the client supports it. $_SESSION['dbcharset'] = "utf8mb4"; // Lower versions only support UTF-8 limited to 3 bytes per character if (mysqli_get_server_version($mylink) < 50503) { $_SESSION['dbcharset'] = "utf8"; } else { if (false !== strpos(mysqli_get_client_info($mylink), 'mysqlnd')) { // mysqlnd 5.0.9+ required if (mysqli_get_client_version($mylink) < 50009) { $_SESSION['dbcharset'] = "utf8"; } } else { // libmysqlclient 5.5.3+ required if (mysqli_get_client_version($mylink) < 50503) { $_SESSION['dbcharset'] = "utf8"; } } } echo graf(span(null, array('class' => 'ui-icon ui-icon-check')) . ' ' . setup_gTxt('using_db', array('{dbname}' => strong(txpspecialchars($_SESSION['ddb']))), 'raw') . ' (' . $_SESSION['dbcharset'] . ')', array('class' => 'alert-block success')); echo setup_config_contents() . n . '</div>'; }
if (empty($expected_methods) && empty($methods)) { printf("ok\n"); } printf("\nClass variables:\n"); $variables = array_keys(get_class_vars(get_class($driver))); sort($variables); foreach ($variables as $k => $var) { printf("%s\n", $var); } printf("\nObject variables:\n"); $variables = array_keys(get_object_vars($driver)); foreach ($variables as $k => $var) { printf("%s\n", $var); } printf("\nMagic, magic properties:\n"); assert(mysqli_get_client_info() === $driver->client_info); printf("driver->client_info = '%s'\n", $driver->client_info); assert(mysqli_get_client_version() === $driver->client_version); printf("driver->client_version = '%s'\n", $driver->client_version); assert($driver->driver_version > 0); printf("driver->driver_version = '%s'\n", $driver->driver_version); assert(in_array($driver->report_mode, array(MYSQLI_REPORT_ALL, MYSQLI_REPORT_STRICT, MYSQLI_REPORT_ERROR, MYSQLI_REPORT_INDEX, MYSQLI_REPORT_OFF))); printf("driver->report_mode = '%s'\n", $driver->report_mode); $driver->report_mode = MYSQLI_REPORT_STRICT; assert($driver->report_mode === MYSQLI_REPORT_STRICT); assert(is_bool($driver->embedded)); printf("driver->embedded = '%s'\n", $driver->embedded); printf("driver->reconnect = '%s'\n", $driver->reconnect); printf("\nAccess to undefined properties:\n"); printf("driver->unknown = '%s'\n", @$driver->unknown); print "done!";
<?php function open_cursor($mysql, $query) { if (!is_object($stmt = $mysql->prepare($query))) { printf("[001] Cannot create statement object for '%s', [%d] %s\n", $query, $mysql->errno, $mysql->error); } $stmt->attr_set(MYSQLI_STMT_ATTR_CURSOR_TYPE, MYSQLI_CURSOR_TYPE_READ_ONLY); return $stmt; } require_once "connect.inc"; $mysql = new my_mysqli($host, $user, $passwd, $db, $port, $socket); if (!$IS_MYSQLND && mysqli_get_client_version() < 50009 || mysqli_get_server_version($mysql) < 50009) { /* we really want to skip it... */ die(var_dump(63)); } $a = array(); for ($i = 0; $i < 3; $i++) { $mysql->query("DROP TABLE IF EXISTS test_067_table_1{$i}"); $mysql->query("CREATE TABLE test_067_table_1{$i} (a int not null) ENGINE=" . $engine); $mysql->query("INSERT INTO test_067_table_1{$i} VALUES (1),(2),(3),(4),(5),(6)"); $stmt[$i] = open_cursor($mysql, "SELECT a FROM test_067_table_1{$i}"); $stmt[$i]->execute(); $stmt[$i]->bind_result($a[$i]); } $cnt = 0; while ($stmt[0]->fetch()) { $stmt[1]->fetch(); $stmt[2]->fetch(); $cnt += $a[0] + $a[1] + $a[2]; }
public function process() { global $wp_version; $mysql_vars = array('key_buffer_size' => true, 'max_allowed_packet' => false, 'max_connections' => false, 'query_cache_limit' => true, 'query_cache_size' => true, 'query_cache_type' => 'ON'); if ($dbq = QM_Collectors::get('db_queries')) { foreach ($dbq->db_objects as $id => $db) { $variables = $db->get_results("\n\t\t\t\t\tSHOW VARIABLES\n\t\t\t\t\tWHERE Variable_name IN ( '" . implode("', '", array_keys($mysql_vars)) . "' )\n\t\t\t\t"); if (is_resource($db->dbh)) { # Old mysql extension $extension = 'mysql'; } else { if (is_object($db->dbh)) { # mysqli or PDO $extension = get_class($db->dbh); } else { # Who knows? $extension = null; } } if (method_exists($db, 'db_version')) { $server = $db->db_version(); } else { $server = null; } if (isset($db->use_mysqli) && $db->use_mysqli) { $client = mysqli_get_client_version(); } else { if (preg_match('|[0-9]{1,2}\\.[0-9]{1,2}\\.[0-9]{1,2}|', mysql_get_client_info(), $matches)) { $client = $matches[0]; } else { $client = null; } } if ($client) { $client_version = implode('.', QM_Util::get_client_version($client)); $client_version = sprintf('%s (%s)', $client, $client_version); } else { $client_version = null; } $info = array('extension' => $extension, 'server version' => $server, 'client version' => $client_version, 'user' => $db->dbuser, 'host' => $db->dbhost, 'database' => $db->dbname); $this->data['db'][$id] = array('info' => $info, 'vars' => $mysql_vars, 'variables' => $variables); } } $this->data['php']['version'] = phpversion(); $this->data['php']['sapi'] = php_sapi_name(); $this->data['php']['user'] = self::get_current_user(); if (defined('HHVM_VERSION')) { $this->data['php']['hhvm'] = HHVM_VERSION; } foreach ($this->php_vars as $setting) { $this->data['php']['variables'][$setting]['after'] = ini_get($setting); } $this->data['php']['error_reporting'] = error_reporting(); $this->data['wp'] = array('version' => $wp_version, 'WP_DEBUG' => self::format_bool_constant('WP_DEBUG'), 'WP_DEBUG_DISPLAY' => self::format_bool_constant('WP_DEBUG_DISPLAY'), 'WP_DEBUG_LOG' => self::format_bool_constant('WP_DEBUG_LOG'), 'SCRIPT_DEBUG' => self::format_bool_constant('SCRIPT_DEBUG'), 'WP_CACHE' => self::format_bool_constant('WP_CACHE'), 'CONCATENATE_SCRIPTS' => self::format_bool_constant('CONCATENATE_SCRIPTS'), 'COMPRESS_SCRIPTS' => self::format_bool_constant('COMPRESS_SCRIPTS'), 'COMPRESS_CSS' => self::format_bool_constant('COMPRESS_CSS'), 'WP_LOCAL_DEV' => self::format_bool_constant('WP_LOCAL_DEV')); if (is_multisite()) { $this->data['wp']['SUNRISE'] = self::format_bool_constant('SUNRISE'); } $server = explode(' ', $_SERVER['SERVER_SOFTWARE']); $server = explode('/', reset($server)); if (isset($server[1])) { $server_version = $server[1]; } else { $server_version = null; } if (isset($_SERVER['SERVER_ADDR'])) { $address = $_SERVER['SERVER_ADDR']; } else { $address = null; } $this->data['server'] = array('name' => $server[0], 'version' => $server_version, 'address' => $address, 'host' => php_uname('n')); }
printf("[002] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); } if (!mysqli_query($link, "INSERT INTO test_bind_result VALUES(120,2999,3999,54,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t 2.6,58.89,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t '206','6.7')")) { printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); } $stmt = mysqli_prepare($link, "SELECT * FROM test_bind_result"); $c = array(0, 0, 0, 0, 0, 0, 0, 0); $b_res = mysqli_stmt_bind_result($stmt, $c[0], $c[1], $c[2], $c[3], $c[4], $c[5], $c[6], $c[7]); mysqli_stmt_execute($stmt); mysqli_stmt_fetch($stmt); mysqli_stmt_fetch($stmt); mysqli_stmt_close($stmt); $result = mysqli_query($link, "select * from test_bind_result"); $d = mysqli_fetch_row($result); mysqli_free_result($result); $test = ""; for ($i = 0; $i < count($c); $i++) { $test .= $c[$i] == $d[$i] ? "1" : "0"; } if ($test == "11111111") { echo "ok\n"; } else { if ($b_res == FALSE && mysqli_get_client_version() > 40100 && mysqli_get_client_version() < 50000 && mysqli_get_server_version($link) > 50000) { echo "error (4.1 library with 5.x server)"; } else { echo "error"; } } mysqli_query($link, "DROP TABLE IF EXISTS test_bind_result"); mysqli_close($link); print "done!";
/** * Set the charset on the current connection * * @param string charset (or array(charset, collation)) * @param resource connection handle * * @return true on success, MDB2 Error Object on failure */ function setCharset($charset, $connection = null) { if (null === $connection) { $connection = $this->getConnection(); if (PEAR::isError($connection)) { return $connection; } } $collation = null; if (is_array($charset) && 2 == count($charset)) { $collation = array_pop($charset); $charset = array_pop($charset); } $client_info = mysqli_get_client_version(); if (OS_WINDOWS && (40111 > $client_info || 50000 <= $client_info && 50006 > $client_info)) { $query = "SET NAMES '" . mysqli_real_escape_string($connection, $charset) . "'"; if (null !== $collation) { $query .= " COLLATE '" . mysqli_real_escape_string($connection, $collation) . "'"; } return $this->_doQuery($query, true, $connection); } if (!($result = mysqli_set_charset($connection, $charset))) { $err = $this->raiseError(null, null, null, 'Could not set client character set', __FUNCTION__); return $err; } return $result; }
<?php $test_table_name = 'test_mysqli_driver_table_1'; require "table.inc"; if (!is_object($driver = new mysqli_driver())) { printf("[001] Failed to create mysqli_driver object\n"); } $client_info = mysqli_get_client_info(); if (($tmp = $driver->client_info) !== $client_info) { printf("[002] Expecting %s/%s, got %s/%s\n", gettype($client_info), $client_info, gettype($tmp), $tmp); } $client_version = mysqli_get_client_version(); if (($tmp = $driver->client_version) !== $client_version) { printf("[003] Expecting %s/%s, got %s/%s\n", gettype($client_version), $client_version, gettype($tmp), $tmp); } if (!is_int($tmp = $driver->driver_version) || 0 == $tmp) { printf("[004] Expecting int/any, got %s/%s\n", gettype($tmp), $tmp); } $all_modes = array(MYSQLI_REPORT_INDEX, MYSQLI_REPORT_ERROR, MYSQLI_REPORT_STRICT, MYSQLI_REPORT_ALL, MYSQLI_REPORT_OFF); $report_mode = $driver->report_mode; if (!is_int($report_mode)) { printf("[005] Expecting int/any, got %s/%s\n", gettype($report_mode), $report_mode); } if (!in_array($report_mode, $all_modes)) { printf("[006] Illegal report mode returned? Got %s, expected %s\n", $report_mode, implode(', ', $all_modes)); } $driver->report_mode = MYSQLI_REPORT_STRICT; $ok = false; try { if ($link = my_mysqli_connect($host, $user . 'unknown_really', $passwd . 'non_empty', $db, $port, $socket)) { printf("[007] Can connect to the server using host=%s, user=%s, passwd=***non_empty, dbname=%s, port=%s, socket=%s\n", $host, $user . 'unknown_really', $db, $port, $socket);
function clientVers() { $orig = @mysqli_get_client_info($this->_conn); $vstr = $this->_findVers($orig); $vint = @mysqli_get_client_version($this->_conn); return array('orig' => $orig, 'vstr' => $vstr, 'vint' => $vint); }
<?php if (!is_int($info = mysqli_get_client_version()) || $info < 100) { printf("[001] Expecting int/any_non_empty, got %s/%s\n", gettype($info), $info); } print "done!";
/** * Get system info * Returns the system info for a WordPress instance * * @access public * @author Daniel J Griffiths * @since 1.0.0 * @global $wpdb * @global object $wpdb Used to query the database * * @param bool $show_inactive Whether or not to show inactive plugins * @param string $id The ID to assign to the returned textarea (Default: system-info-box) * @param string $class The class to assign to the returned textarea (Default: none) * * @return string $return A string containing all system info */ public function get($show_inactive = false, $id = 'system-info-box', $class = null) { global $wpdb; if (!defined('SSINFO_VERSION')) { define('SSINFO_VERSION', '1.0.0'); } // We need the Browser class! if (!class_exists('Browser')) { require_once 'browser.php'; } $browser = new Browser(); // Get theme info for this WordPress version $theme_data = wp_get_theme(); $theme = $theme_data->Name . ' ' . $theme_data->Version; $return = '<textarea readonly="readonly" onclick="this.focus(); this.select()" id="' . $id . '"' . ($class != null ? ' class="' . $class . '"' : '') . ' title="To copy the system info, click below and press Ctrl+C (PC) or Cmd+C (Mac).">'; $return .= '### Begin System Info ###' . "\n\n"; do_action('simple_system_info_before'); // Start with the basice... $return .= '-- Site Info' . "\n\n"; $return .= 'Site URL: ' . site_url() . "\n"; $return .= 'Home URL: ' . home_url() . "\n"; $return .= 'Multisite: ' . (is_multisite() ? 'Yes' : 'No') . "\n"; if (has_filter('ssi_after_site_info')) { $return .= apply_filters('ssi_after_site_info', $return); } // The local users' browser information, handled by the Browser class $return .= "\n" . '-- User Browser' . "\n\n"; $return .= $browser; if (has_filter('ssi_after_user_browser')) { $return .= apply_filters('ssi_after_user_browser', $return); } // WordPress configuration $return .= "\n" . '-- WordPress Configuration' . "\n\n"; $return .= 'Version: ' . get_bloginfo('version') . "\n"; $return .= 'Permalink Structure: ' . (get_option('permalink_structure') ? get_option('permalink_structure') : 'Default') . "\n"; $return .= 'Active Theme: ' . $theme . "\n"; $return .= 'Show On Front: ' . get_option('show_on_front') . "\n"; // Only show page specs if frontpage is set to 'page' if (get_option('show_on_front') == 'page') { $front_page_id = get_option('page_on_front'); $blog_page_id = get_option('page_for_posts'); $return .= 'Page On Front: ' . ($front_page_id != 0 ? get_the_title($front_page_id) . ' (#' . $front_page_id . ')' : 'Unset') . "\n"; $return .= 'Page For Posts: ' . ($blog_page_id != 0 ? get_the_title($blog_page_id) . ' (#' . $blog_page_id . ')' : 'Unset') . "\n"; } // Make sure wp_remote_post() is working $request['cmd'] = '_notify-validate'; $params = array('sslverify' => false, 'timeout' => 60, 'user-agent' => 'SSInfo/' . SSINFO_VERSION, 'body' => $request); $response = wp_remote_post('https://www.paypal.com/cgi-bin/webscr', $params); if (!is_wp_error($response) && $response['response']['code'] >= 200 && $response['response']['code'] < 300) { $WP_REMOTE_POST = 'wp_remote_post() works'; } else { $WP_REMOTE_POST = 'wp_remote_post() does not work'; } $return .= 'Remote Post: ' . $WP_REMOTE_POST . "\n"; $return .= 'Table Prefix: ' . 'Length: ' . strlen($wpdb->prefix) . ' Status: ' . (strlen($wpdb->prefix) > 16 ? 'ERROR: Too long' : 'Acceptable') . "\n"; $return .= 'WP_DEBUG: ' . (defined('WP_DEBUG') ? WP_DEBUG ? 'Enabled' : 'Disabled' : 'Not set') . "\n"; $return .= 'Memory Limit: ' . WP_MEMORY_LIMIT . "\n"; if (has_filter('ssi_after_wordpress_config')) { $return .= apply_filters('ssi_after_wordpress_config', $return); } // WordPress active plugins $return .= "\n" . '-- WordPress Active Plugins' . "\n\n"; $plugins = get_plugins(); $active_plugins = get_option('active_plugins', array()); foreach ($plugins as $plugin_path => $plugin) { if (!in_array($plugin_path, $active_plugins)) { continue; } //if( $plugin['Name'] !== 'Redux Framework' ) continue; $return .= $plugin['Name'] . ': ' . $plugin['Version'] . "\n"; } if (has_filter('ssi_after_wordpress_plugins')) { $return .= apply_filters('ssi_after_wordpress_plugins', $return); } // WordPress inactive plugins if ($show_inactive == true) { $return .= "\n" . '-- WordPress Inactive Plugins' . "\n\n"; foreach ($plugins as $plugin_path => $plugin) { if (in_array($plugin_path, $active_plugins)) { continue; } $return .= $plugin['Name'] . ': ' . $plugin['Version'] . "\n"; } } if (has_filter('ssi_after_wordpress_plugins_inactive')) { $return .= apply_filters('ssi_after_wordpress_plugins_inactive', $return); } // WordPress Multisite active plugins if (is_multisite()) { $return .= "\n" . '-- Network Active Plugins' . "\n\n"; $plugins = wp_get_active_network_plugins(); $active_plugins = get_site_option('active_sitewide_plugins', array()); foreach ($plugins as $plugin_path) { $plugin_base = plugin_basename($plugin_path); if (!array_key_exists($plugin_base, $active_plugins)) { continue; } $return .= $plugin['Name'] . ': ' . $plugin['Version'] . "\n"; } if (has_filter('ssi_after_wordpress_ms_plugins')) { $return .= apply_filters('ssi_after_wordpress_ms_plugins', $return); } // WordPress Multisite inactive plugins if ($show_inactive == true) { $return .= "\n" . '-- Network Inactive Plugins' . "\n\n"; foreach ($plugins as $plugin_path) { $plugin_base = plugin_basename($plugin_path); if (array_key_exists($plugin_base, $active_plugins)) { continue; } $return .= $plugin['Name'] . ': ' . $plugin['Version'] . "\n"; } } } if (has_filter('ssi_after_wordpress_ms_plugins_inactive')) { $return .= apply_filters('ssi_after_wordpress_ms_plugins_inactive', $return); } // Server configuration (really just versioning) $return .= "\n" . '-- Webserver Configuration' . "\n\n"; $return .= 'PHP Version: ' . PHP_VERSION . "\n"; if (function_exists('mysqli_get_client_version')) { $return .= 'MySQL Version: ' . mysqli_get_client_version() . "\n"; } $return .= 'Webserver Info: ' . $_SERVER['SERVER_SOFTWARE'] . "\n"; if (has_filter('ssi_after_webserver_config')) { $return .= apply_filters('ssi_after_webserver_config', $return); } // PHP configs... now we're getting to the important stuff $return .= "\n" . '-- PHP Configuration' . "\n\n"; $return .= 'Safe Mode: ' . (ini_get('safe_mode') ? 'Yes' : 'No') . "\n"; $return .= 'Memory Limit: ' . ini_get('memory_limit') . "\n"; $return .= 'Upload Max Size: ' . ini_get('upload_max_filesize') . "\n"; $return .= 'Post Max Size: ' . ini_get('post_max_size') . "\n"; $return .= 'Upload Max Filesize: ' . ini_get('upload_max_filesize') . "\n"; $return .= 'Time Limit: ' . ini_get('max_execution_time') . "\n"; $return .= 'Max Input Vars: ' . ini_get('max_input_vars') . "\n"; $return .= 'Display Errors: ' . (ini_get('display_errors') ? 'On (' . ini_get('display_errors') . ')' : 'N/A') . "\n"; if (has_filter('ssi_after_php_config')) { $return .= apply_filters('ssi_after_php_config', $return); } // PHP extensions and such $return .= "\n" . '-- PHP Extensions' . "\n\n"; $return .= 'cURL: ' . (function_exists('curl_init') ? 'Supported' : 'Not Supported') . "\n"; $return .= 'fsockopen: ' . (function_exists('fsockopen') ? 'Supported' : 'Not Supported') . "\n"; $return .= 'SOAP Client: ' . (class_exists('SoapClient') ? 'Installed' : 'Not Installed') . "\n"; $return .= 'Suhosin: ' . (extension_loaded('suhosin') ? 'Installed' : 'Not Installed') . "\n"; if (has_filter('ssi_after_php_ext')) { $return .= apply_filters('ssi_after_php_ext', $return); } // Session stuff $return .= "\n" . '-- Session Configuration' . "\n\n"; $return .= 'Session: ' . (isset($_SESSION) ? 'Enabled' : 'Disabled') . "\n"; // The rest of this is only relevant is session is enabled if (isset($_SESSION)) { $return .= 'Session Name: ' . esc_html(ini_get('session.name')) . "\n"; $return .= 'Cookie Path: ' . esc_html(ini_get('session.cookie_path')) . "\n"; $return .= 'Save Path: ' . esc_html(ini_get('session.save_path')) . "\n"; $return .= 'Use Cookies: ' . (ini_get('session.use_cookies') ? 'On' : 'Off') . "\n"; $return .= 'Use Only Cookies: ' . (ini_get('session.use_only_cookies') ? 'On' : 'Off') . "\n"; } if (has_filter('ssi_after_session_config')) { $return .= apply_filters('ssi_after_session_config', $return); } do_action('ssi_after'); $return .= "\n" . '### End System Info ###'; $return .= '</textarea>'; return $return; }
} if (!is_null($tmp = @mysqli_stmt_attr_get($link))) { printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); } if (!is_null($tmp = @mysqli_stmt_attr_get($link, $link))) { printf("[003] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); } require 'table.inc'; if (!is_null($tmp = @mysqli_stmt_attr_get($link, $link))) { printf("[004] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); } $valid_attr = array("max_length" => MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH); if (mysqli_get_client_version() > 50003) { $valid_attr["cursor_type"] = MYSQLI_STMT_ATTR_CURSOR_TYPE; } if ($IS_MYSQLND && mysqli_get_client_version() > 50007) { $valid_attr["prefetch_rows"] = MYSQLI_STMT_ATTR_PREFETCH_ROWS; } do { $invalid_attr = mt_rand(0, 10000); } while (in_array($invalid_attr, $valid_attr)); $stmt = mysqli_stmt_init($link); mysqli_stmt_prepare($stmt, 'SELECT * FROM test'); if (false !== ($tmp = @mysqli_stmt_attr_get($stmt, $invalid_attr))) { printf("[005] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); } foreach ($valid_attr as $k => $attr) { if (false === ($tmp = mysqli_stmt_attr_get($stmt, $attr))) { printf("[006] Expecting any type, but not boolean/false, got %s/%s for attribute %s/%s\n", gettype($tmp), $tmp, $k, $attr); } }
<?php require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'; $expected = array('MYSQL_ATTR_USE_BUFFERED_QUERY' => true, 'MYSQL_ATTR_LOCAL_INFILE' => true, 'MYSQL_ATTR_DIRECT_QUERY' => true, 'MYSQL_ATTR_FOUND_ROWS' => true, 'MYSQL_ATTR_IGNORE_SPACE' => true, 'MYSQL_ATTR_INIT_COMMAND' => true, "MYSQL_ATTR_SSL_KEY" => true, "MYSQL_ATTR_SSL_CERT" => true, "MYSQL_ATTR_SSL_CA" => true, "MYSQL_ATTR_SSL_CAPATH" => true, "MYSQL_ATTR_SSL_CIPHER" => true, "MYSQL_ATTR_COMPRESS" => true); if (!MySQLPDOTest::isPDOMySQLnd()) { $expected['MYSQL_ATTR_MAX_BUFFER_SIZE'] = true; $expected['MYSQL_ATTR_READ_DEFAULT_FILE'] = true; $expected['MYSQL_ATTR_READ_DEFAULT_GROUP'] = true; } if (extension_loaded('mysqlnd')) { $expected['MYSQL_ATTR_SERVER_PUBLIC_KEY'] = true; } else { if (extension_loaded('mysqli')) { if (mysqli_get_client_version() > 50605) { $expected['MYSQL_ATTR_SERVER_PUBLIC_KEY'] = true; } } else { if (MySQLPDOTest::getClientVersion(MySQLPDOTest::factory()) > 50605) { /* XXX the MySQL client library version isn't exposed with any constants, the single possibility is to use the PDO::getAttribute(). This however will fail with no connection. */ $expected['MYSQL_ATTR_SERVER_PUBLIC_KEY'] = true; } } } /* TODO MYSQLI_OPT_CONNECT_TIMEOUT != PDO::ATTR_TIMEOUT (integer) Sets the timeout value in seconds for communications with the database. ^ Potential BUG, PDO::ATTR_TIMEOUT is used in pdo_mysql_handle_factory
$user = getenv("MYSQL_TEST_USER") ? getenv("MYSQL_TEST_USER") : "root"; $passwd = getenv("MYSQL_TEST_PASSWD") ? getenv("MYSQL_TEST_PASSWD") : ""; $db = getenv("MYSQL_TEST_DB") ? getenv("MYSQL_TEST_DB") : "test"; class ExtMySQLiDriver extends mysqli_driver { public function __get($name) { echo "ExtMySQLiDriver::__get({$name});\n"; } public function __set($name, $value) { echo "ExtMySQLiDriver::__set({$name}, {$value});\n"; } } $driver = new ExtMySQLiDriver(); // Impl-level. var_dump($driver->client_info); var_dump(mysqli_get_client_info() === $driver->client_info); var_dump($driver->client_version); var_dump(mysqli_get_client_version() === $driver->client_version); var_dump($driver->driver_version); var_dump($driver->reconnect); $driver->reconnect = true; var_dump($driver->reconnect === true); var_dump($driver->report_mode); var_dump(in_array($driver->report_mode, array(MYSQLI_REPORT_ALL, MYSQLI_REPORT_STRICT, MYSQLI_REPORT_ERROR, MYSQLI_REPORT_INDEX, MYSQLI_REPORT_OFF))); $driver->report_mode = MYSQLI_REPORT_STRICT; var_dump($driver->report_mode === MYSQLI_REPORT_STRICT); // User-level var_dump($driver->nonExisting); $driver->nonExisting = 1;
if (!empty($expected_object_variables)) { printf("Dumping list of missing object variables\n"); var_dump($expected_object_variables); } if (!empty($variables)) { printf("Dumping list of unexpected object variables\n"); var_dump($variables); } echo "ok\n"; printf("\nMagic, magic properties:\n"); assert(mysqli_affected_rows($link) === $mysqli->affected_rows); printf("mysqli->affected_rows = '%s'/%s ('%s'/%s)\n", $mysqli->affected_rows, gettype($mysqli->affected_rows), mysqli_affected_rows($link), gettype(mysqli_affected_rows($link))); 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($link) === $mysqli->errno); printf("mysqli->errno = '%s'/%s ('%s'/%s)\n", $mysqli->errno, gettype($mysqli->errno), mysqli_errno($link), gettype(mysqli_errno($link))); assert(mysqli_error($link) === $mysqli->error); printf("mysqli->error = '%s'/%s ('%s'/%s)\n", $mysqli->error, gettype($mysqli->error), mysqli_error($link), gettype(mysqli_error($link))); if (version_compare(PHP_VERSION, '5.3.99', '>')) { assert(mysqli_error_list($link) === $mysqli->error_list); assert(is_array($mysqli->error_list)); } assert(mysqli_field_count($link) === $mysqli->field_count); printf("mysqli->field_count = '%s'/%s ('%s'/%s)\n", $mysqli->field_count, gettype($mysqli->field_count), mysqli_field_count($link), gettype(mysqli_field_count($link))); assert(mysqli_insert_id($link) === $mysqli->insert_id); printf("mysqli->insert_id = '%s'/%s ('%s'/%s)\n", $mysqli->insert_id, gettype($mysqli->insert_id), mysqli_insert_id($link), gettype(mysqli_insert_id($link))); assert(mysqli_sqlstate($link) === $mysqli->sqlstate); printf("mysqli->sqlstate = '%s'/%s ('%s'/%s)\n", $mysqli->sqlstate, gettype($mysqli->sqlstate), mysqli_sqlstate($link), gettype(mysqli_sqlstate($link))); assert(soundex(mysqli_stat($link)) == soundex($mysqli->stat));
$stmt->bind_result($id, $label); $results2 = array(); while ($stmt->fetch()) { $results2[$id] = $label; } $stmt->close(); if ($results != $results2) { printf("[019] Results should not differ. Dumping both result sets.\n"); var_dump($results); var_dump($results2); } } // // MYSQLI_STMT_ATTR_PREFETCH_ROWS // if (mysqli_get_client_version() > 50007) { $stmt = mysqli_stmt_init($link); $stmt->prepare("SELECT id, label FROM test_mysqli_stmt_attr_set_table_1"); if (true !== ($tmp = $stmt->attr_set(MYSQLI_STMT_ATTR_PREFETCH_ROWS, 1))) { printf("[020] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp); } $stmt->execute(); $id = $label = NULL; $stmt->bind_result($id, $label); $results = array(); while ($stmt->fetch()) { $results[$id] = $label; } $stmt->close(); if (empty($results)) { printf("[021] Results should not be empty, subsequent tests will probably fail!\n");
func_mysqli_fetch_array($mysqli, $engine, "SMALLINT", -32768, "-32768", 100); func_mysqli_fetch_array($mysqli, $engine, "SMALLINT", 32767, "32767", 110); func_mysqli_fetch_array($mysqli, $engine, "SMALLINT", NULL, NULL, 120); func_mysqli_fetch_array($mysqli, $engine, "SMALLINT UNSIGNED", 65535, "65535", 130); func_mysqli_fetch_array($mysqli, $engine, "SMALLINT UNSIGNED", NULL, NULL, 140); func_mysqli_fetch_array($mysqli, $engine, "MEDIUMINT", -8388608, "-8388608", 150); func_mysqli_fetch_array($mysqli, $engine, "MEDIUMINT", 8388607, "8388607", 160); func_mysqli_fetch_array($mysqli, $engine, "MEDIUMINT", NULL, NULL, 170); func_mysqli_fetch_array($mysqli, $engine, "MEDIUMINT UNSIGNED", 16777215, "16777215", 180); func_mysqli_fetch_array($mysqli, $engine, "MEDIUMINT UNSIGNED", NULL, NULL, 190); func_mysqli_fetch_array($mysqli, $engine, "INTEGER", -2147483648, "-2147483648", 200); func_mysqli_fetch_array($mysqli, $engine, "INTEGER", 2147483647, "2147483647", 210); func_mysqli_fetch_array($mysqli, $engine, "INTEGER", NULL, NULL, 220); func_mysqli_fetch_array($mysqli, $engine, "INTEGER UNSIGNED", "4294967295", "4294967295", 230); func_mysqli_fetch_array($mysqli, $engine, "INTEGER UNSIGNED", NULL, NULL, 240); if ($IS_MYSQLND || mysqli_get_server_version($link) >= 51000 && mysqli_get_client_version($link) >= 51000) { func_mysqli_fetch_array($mysqli, $engine, "BIGINT", "-9223372036854775808", "-9223372036854775808", 250); func_mysqli_fetch_array($mysqli, $engine, "BIGINT", NULL, NULL, 260); func_mysqli_fetch_array($mysqli, $engine, "BIGINT UNSIGNED", "18446744073709551615", "18446744073709551615", 270); func_mysqli_fetch_array($mysqli, $engine, "BIGINT UNSIGNED", NULL, NULL, 280); } func_mysqli_fetch_array($mysqli, $engine, "FLOAT", (string) (-9.223372036854776E+18 - 1.1), "-9.22337e+18", 290, "/-9\\.22337e\\+?[0]?18/iu"); func_mysqli_fetch_array($mysqli, $engine, "FLOAT", NULL, NULL, 300); func_mysqli_fetch_array($mysqli, $engine, "FLOAT UNSIGNED", (string) (1.8446744073709552E+19 + 1.1), "1.84467e+?19", 310, "/1\\.84467e\\+?[0]?19/iu"); func_mysqli_fetch_array($mysqli, $engine, "FLOAT UNSIGNED ", NULL, NULL, 320); func_mysqli_fetch_array($mysqli, $engine, "DOUBLE(10,2)", "-99999999.99", "-99999999.99", 330); func_mysqli_fetch_array($mysqli, $engine, "DOUBLE(10,2)", NULL, NULL, 340); func_mysqli_fetch_array($mysqli, $engine, "DOUBLE(10,2) UNSIGNED", "99999999.99", "99999999.99", 350); func_mysqli_fetch_array($mysqli, $engine, "DOUBLE(10,2) UNSIGNED", NULL, NULL, 360); func_mysqli_fetch_array($mysqli, $engine, "DECIMAL(10,2)", "-99999999.99", "-99999999.99", 370); func_mysqli_fetch_array($mysqli, $engine, "DECIMAL(10,2)", NULL, NULL, 380);