Пример #1
0
 public function ServerVersion()
 {
     if (empty($this->server_version)) {
         $this->server_version = mysqli_get_server_version($this->connectid);
     }
     return $this->server_version;
 }
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()));
}
Пример #3
0
 public function checkMySQLVersion()
 {
     $result = mysqli_get_server_version();
     $mainVersion = round($result / 10000, 0);
     $minorVersion = round(($result - $mainVersion * 10000) / 100, 0);
     $subVersion = $result - $minorVersion * 100 - $mainVersion * 10000;
     return 1 == version_compare($mainVersion . '.' . $minorVersion . '.' . $subVersion, '4.1', '>=');
 }
Пример #4
0
 /**
  * Returns a string representing the version of the MySQL server that the MySQLi extension is connected to.
  *
  * @param DB $db
  *
  * @return string
  */
 public static function get_mysql_server_version(DB $db)
 {
     static $_mysqli_server_version = null;
     if ($_mysqli_server_version === null) {
         $_mysqli_server_version = \mysqli_get_server_version($db->getLink());
     }
     return $_mysqli_server_version;
 }
Пример #5
0
 function checkMysqlServerVersion()
 {
     $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_server_version($mysqli);
 }
Пример #6
0
 /**
  * Connect to database
  *
  * @param array $options
  * @return array
  */
 public function connect($options)
 {
     $result = ['version' => null, 'status' => 0, 'error' => [], 'errno' => 0, 'success' => false];
     // we could pass an array or connection string right a way
     $connection = mysqli_connect($options['host'], $options['username'], $options['password'], $options['dbname'], $options['port']);
     if ($connection) {
         $this->db_resource = $connection;
         $this->connect_options = $options;
         $this->commit_status = 0;
         mysqli_set_charset($connection, 'utf8');
         $result['version'] = mysqli_get_server_version($connection);
         $result['status'] = 1;
         $result['success'] = true;
     } else {
         $result['error'][] = mysqli_connect_error();
         $result['errno'] = mysqli_connect_errno();
     }
     return $result;
 }
Пример #7
0
 /**
  * Db_Mysql constructor.
  *
  * @param  array $args
  * @throws \Exception
  */
 public function __construct(array $args)
 {
     if (!empty($args['charset'])) {
         $args['charset'] = $this->fixMysqlCharset($args['charset']);
     }
     $this->args = $args;
     if (!is_callable('mysql_connect')) {
         throw new \Exception(__METHOD__ . ': mysql_connect is not supported.');
     }
     $this->conn = mysql_connect($args['host'], $args['user'], $args['pass']);
     if ($this->conn === false) {
         throw new \Exception(__METHOD__ . ': failed to connect to MySQL server.');
     }
     if (!mysql_select_db($args['name'], $this->conn)) {
         throw new \Exception(__METHOD__ . ': could not select database.');
     }
     $this->serverVersion = @mysqli_get_server_version($this->conn);
     if (!empty($args['charset'])) {
         if (!mysql_set_charset($args['charset'], $this->conn)) {
             @mysql_query("SET NAMES {$args['charset']}");
         }
     }
 }
Пример #8
0
function ss_get_mysql_stats($options)
{
    # Process connection options.
    global $debug, $mysql_user, $mysql_pass, $cache_dir, $poll_time, $chk_options, $mysql_port, $mysql_ssl, $mysql_ssl_key, $mysql_ssl_cert, $mysql_ssl_ca, $mysql_connection_timeout, $heartbeat, $heartbeat_table, $heartbeat_server_id, $heartbeat_utc;
    $user = isset($options['user']) ? $options['user'] : $mysql_user;
    $pass = isset($options['pass']) ? $options['pass'] : $mysql_pass;
    $host = $options['host'];
    $port = isset($options['port']) ? $options['port'] : $mysql_port;
    $connection_timeout = isset($options['connection-timeout']) ? $options['connection-timeout'] : $mysql_connection_timeout;
    $heartbeat_server_id = isset($options['server-id']) ? $options['server-id'] : $heartbeat_server_id;
    $sanitized_host = str_replace(array(":", "/"), array("", "_"), $host);
    $cache_file = "{$cache_dir}/{$sanitized_host}-mysql_cacti_stats.txt" . ($port != 3306 ? ":{$port}" : '');
    debug("Cache file is {$cache_file}");
    # First, check the cache.
    $fp = null;
    if ($cache_dir && !array_key_exists('nocache', $options)) {
        if ($fp = fopen($cache_file, 'a+')) {
            $locked = flock($fp, 1);
            # LOCK_SH
            if ($locked) {
                if (filesize($cache_file) > 0 && filectime($cache_file) + $poll_time / 2 > time() && ($arr = file($cache_file))) {
                    # The cache file is good to use.
                    debug("Using the cache file");
                    fclose($fp);
                    return $arr[0];
                } else {
                    debug("The cache file seems too small or stale");
                    # Escalate the lock to exclusive, so we can write to it.
                    if (flock($fp, 2)) {
                        # LOCK_EX
                        # We might have blocked while waiting for that LOCK_EX, and
                        # another process ran and updated it.  Let's see if we can just
                        # return the data now:
                        if (filesize($cache_file) > 0 && filectime($cache_file) + $poll_time / 2 > time() && ($arr = file($cache_file))) {
                            # The cache file is good to use.
                            debug("Using the cache file");
                            fclose($fp);
                            return $arr[0];
                        }
                        ftruncate($fp, 0);
                        # Now it's ready for writing later.
                    }
                }
            } else {
                $fp = null;
                debug("Couldn't lock the cache file, ignoring it");
            }
        } else {
            $fp = null;
            debug("Couldn't open the cache file");
        }
    } else {
        debug("Caching is disabled.");
    }
    # Connect to MySQL.
    debug(array('Connecting to', $host, $port, $user, $pass));
    if (!extension_loaded('mysqli')) {
        debug("PHP MySQLi extension is not loaded");
        die("PHP MySQLi extension is not loaded");
    }
    if ($mysql_ssl) {
        $conn = mysqli_init();
        $conn->options(MYSQLI_OPT_CONNECT_TIMEOUT, $connection_timeout);
        mysqli_ssl_set($conn, $mysql_ssl_key, $mysql_ssl_cert, $mysql_ssl_ca, NULL, NULL);
        mysqli_real_connect($conn, $host, $user, $pass, NULL, $port);
    } else {
        $conn = mysqli_init();
        $conn->options(MYSQLI_OPT_CONNECT_TIMEOUT, $connection_timeout);
        mysqli_real_connect($conn, $host, $user, $pass, NULL, $port);
    }
    if (mysqli_connect_errno()) {
        debug("MySQL connection failed: " . mysqli_connect_error());
        die("ERROR: " . mysqli_connect_error());
    }
    # MySQL server version.
    # The form of this version number is main_version * 10000 + minor_version * 100 + sub_version
    # i.e. version 5.5.44 is 50544.
    $mysql_version = mysqli_get_server_version($conn);
    debug("MySQL server version is " . $mysql_version);
    # Set up variables.
    $status = array('relay_log_space' => null, 'binary_log_space' => null, 'current_transactions' => 0, 'locked_transactions' => 0, 'active_transactions' => 0, 'innodb_locked_tables' => 0, 'innodb_tables_in_use' => 0, 'innodb_lock_structs' => 0, 'innodb_lock_wait_secs' => 0, 'innodb_sem_waits' => 0, 'innodb_sem_wait_time_ms' => 0, 'State_closing_tables' => 0, 'State_copying_to_tmp_table' => 0, 'State_end' => 0, 'State_freeing_items' => 0, 'State_init' => 0, 'State_locked' => 0, 'State_login' => 0, 'State_preparing' => 0, 'State_reading_from_net' => 0, 'State_sending_data' => 0, 'State_sorting_result' => 0, 'State_statistics' => 0, 'State_updating' => 0, 'State_writing_to_net' => 0, 'State_none' => 0, 'State_other' => 0);
    # Get SHOW STATUS and convert the name-value array into a simple
    # associative array.
    $result = run_query("SHOW /*!50002 GLOBAL */ STATUS", $conn);
    foreach ($result as $row) {
        $status[$row[0]] = $row[1];
    }
    # Get SHOW VARIABLES and do the same thing, adding it to the $status array.
    $result = run_query("SHOW VARIABLES", $conn);
    foreach ($result as $row) {
        $status[$row[0]] = $row[1];
    }
    # Get SHOW SLAVE STATUS, and add it to the $status array.
    if ($chk_options['slave']) {
        # Leverage lock-free SHOW SLAVE STATUS if available
        $result = run_query("SHOW SLAVE STATUS NONBLOCKING", $conn);
        if (!$result) {
            $result = run_query("SHOW SLAVE STATUS NOLOCK", $conn);
            if (!$result) {
                $result = run_query("SHOW SLAVE STATUS", $conn);
            }
        }
        $slave_status_rows_gotten = 0;
        foreach ($result as $row) {
            $slave_status_rows_gotten++;
            # Must lowercase keys because different MySQL versions have different
            # lettercase.
            $row = array_change_key_case($row, CASE_LOWER);
            $status['relay_log_space'] = $row['relay_log_space'];
            $status['slave_lag'] = $row['seconds_behind_master'];
            # Check replication heartbeat, if present.
            if ($heartbeat) {
                if ($heartbeat_utc) {
                    $now_func = 'UNIX_TIMESTAMP(UTC_TIMESTAMP)';
                } else {
                    $now_func = 'UNIX_TIMESTAMP()';
                }
                $result2 = run_query("SELECT MAX({$now_func} - ROUND(UNIX_TIMESTAMP(ts)))" . " AS delay FROM {$heartbeat_table}" . " WHERE {$heartbeat_server_id} = 0 OR server_id = {$heartbeat_server_id}", $conn);
                $slave_delay_rows_gotten = 0;
                foreach ($result2 as $row2) {
                    $slave_delay_rows_gotten++;
                    if ($row2 && is_array($row2) && array_key_exists('delay', $row2)) {
                        $status['slave_lag'] = $row2['delay'];
                    } else {
                        debug("Couldn't get slave lag from {$heartbeat_table}");
                    }
                }
                if ($slave_delay_rows_gotten == 0) {
                    debug("Got nothing from heartbeat query");
                }
            }
            # Scale slave_running and slave_stopped relative to the slave lag.
            $status['slave_running'] = $row['slave_sql_running'] == 'Yes' ? $status['slave_lag'] : 0;
            $status['slave_stopped'] = $row['slave_sql_running'] == 'Yes' ? 0 : $status['slave_lag'];
        }
        if ($slave_status_rows_gotten == 0) {
            debug("Got nothing from SHOW SLAVE STATUS");
        }
    }
    # Get SHOW MASTER STATUS, and add it to the $status array.
    if ($chk_options['master'] && array_key_exists('log_bin', $status) && $status['log_bin'] == 'ON') {
        # See issue #8
        $binlogs = array(0);
        $result = run_query("SHOW MASTER LOGS", $conn);
        foreach ($result as $row) {
            $row = array_change_key_case($row, CASE_LOWER);
            # Older versions of MySQL may not have the File_size column in the
            # results of the command.  Zero-size files indicate the user is
            # deleting binlogs manually from disk (bad user! bad!).
            if (array_key_exists('file_size', $row) && $row['file_size'] > 0) {
                $binlogs[] = $row['file_size'];
            }
        }
        if (count($binlogs)) {
            $status['binary_log_space'] = to_int(array_sum($binlogs));
        }
    }
    # Get SHOW PROCESSLIST and aggregate it by state, then add it to the array
    # too.
    if ($chk_options['procs']) {
        $result = run_query('SHOW PROCESSLIST', $conn);
        foreach ($result as $row) {
            $state = $row['State'];
            if (is_null($state)) {
                $state = 'NULL';
            }
            if ($state == '') {
                $state = 'none';
            }
            # MySQL 5.5 replaces the 'Locked' state with a variety of "Waiting for
            # X lock" types of statuses.  Wrap these all back into "Locked" because
            # we don't really care about the type of locking it is.
            $state = preg_replace('/^(Table lock|Waiting for .*lock)$/', 'Locked', $state);
            $state = str_replace(' ', '_', strtolower($state));
            if (array_key_exists("State_{$state}", $status)) {
                increment($status, "State_{$state}", 1);
            } else {
                increment($status, "State_other", 1);
            }
        }
    }
    # Get SHOW ENGINES to be able to determine whether InnoDB is present.
    $engines = array();
    $result = run_query("SHOW ENGINES", $conn);
    foreach ($result as $row) {
        $engines[$row[0]] = $row[1];
    }
    # Get SHOW INNODB STATUS and extract the desired metrics from it, then add
    # those to the array too.
    if ($chk_options['innodb'] && array_key_exists('InnoDB', $engines) && $engines['InnoDB'] == 'YES' || $engines['InnoDB'] == 'DEFAULT') {
        $result = run_query("SHOW /*!50000 ENGINE*/ INNODB STATUS", $conn);
        $istatus_text = $result[0]['Status'];
        $istatus_vals = get_innodb_array($istatus_text, $mysql_version);
        # Get response time histogram from Percona Server or MariaDB if enabled.
        if ($chk_options['get_qrt'] && (isset($status['have_response_time_distribution']) && $status['have_response_time_distribution'] == 'YES' || isset($status['query_response_time_stats']) && $status['query_response_time_stats'] == 'ON')) {
            debug('Getting query time histogram');
            $i = 0;
            $result = run_query("SELECT `count`, ROUND(total * 1000000) AS total " . "FROM INFORMATION_SCHEMA.QUERY_RESPONSE_TIME " . "WHERE `time` <> 'TOO LONG'", $conn);
            foreach ($result as $row) {
                if ($i > 13) {
                    # It's possible that the number of rows returned isn't 14.
                    # Don't add extra status counters.
                    break;
                }
                $count_key = sprintf("Query_time_count_%02d", $i);
                $total_key = sprintf("Query_time_total_%02d", $i);
                $status[$count_key] = $row['count'];
                $status[$total_key] = $row['total'];
                $i++;
            }
            # It's also possible that the number of rows returned is too few.
            # Don't leave any status counters unassigned; it will break graphs.
            while ($i <= 13) {
                $count_key = sprintf("Query_time_count_%02d", $i);
                $total_key = sprintf("Query_time_total_%02d", $i);
                $status[$count_key] = 0;
                $status[$total_key] = 0;
                $i++;
            }
        } else {
            debug('Not getting time histogram because it is not enabled');
        }
        # Override values from InnoDB parsing with values from SHOW STATUS,
        # because InnoDB status might not have everything and the SHOW STATUS is
        # to be preferred where possible.
        $overrides = array('Innodb_buffer_pool_pages_data' => 'database_pages', 'Innodb_buffer_pool_pages_dirty' => 'modified_pages', 'Innodb_buffer_pool_pages_free' => 'free_pages', 'Innodb_buffer_pool_pages_total' => 'pool_size', 'Innodb_data_fsyncs' => 'file_fsyncs', 'Innodb_data_pending_reads' => 'pending_normal_aio_reads', 'Innodb_data_pending_writes' => 'pending_normal_aio_writes', 'Innodb_os_log_pending_fsyncs' => 'pending_log_flushes', 'Innodb_pages_created' => 'pages_created', 'Innodb_pages_read' => 'pages_read', 'Innodb_pages_written' => 'pages_written', 'Innodb_rows_deleted' => 'rows_deleted', 'Innodb_rows_inserted' => 'rows_inserted', 'Innodb_rows_read' => 'rows_read', 'Innodb_rows_updated' => 'rows_updated', 'Innodb_buffer_pool_reads' => 'pool_reads', 'Innodb_buffer_pool_read_requests' => 'pool_read_requests');
        # If the SHOW STATUS value exists, override...
        foreach ($overrides as $key => $val) {
            if (array_key_exists($key, $status)) {
                debug("Override {$key}");
                $istatus_vals[$val] = $status[$key];
            }
        }
        # Now copy the values into $status.
        foreach ($istatus_vals as $key => $val) {
            $status[$key] = $istatus_vals[$key];
        }
    }
    # Make table_open_cache backwards-compatible (issue 63).
    if (array_key_exists('table_open_cache', $status)) {
        $status['table_cache'] = $status['table_open_cache'];
    }
    # Compute how much of the key buffer is used and unflushed (issue 127).
    $status['Key_buf_bytes_used'] = big_sub($status['key_buffer_size'], big_multiply($status['Key_blocks_unused'], $status['key_cache_block_size']));
    $status['Key_buf_bytes_unflushed'] = big_multiply($status['Key_blocks_not_flushed'], $status['key_cache_block_size']);
    if (array_key_exists('unflushed_log', $status) && $status['unflushed_log']) {
        # TODO: I'm not sure what the deal is here; need to debug this.  But the
        # unflushed log bytes spikes a lot sometimes and it's impossible for it to
        # be more than the log buffer.
        debug("Unflushed log: {$status['unflushed_log']}");
        $status['unflushed_log'] = max($status['unflushed_log'], $status['innodb_log_buffer_size']);
    }
    # Define the variables to output.  I use shortened variable names so maybe
    # it'll all fit in 1024 bytes for Cactid and Spine's benefit.  Strings must
    # have some non-hex characters (non a-f0-9) to avoid a Cacti bug.  This list
    # must come right after the word MAGIC_VARS_DEFINITIONS.  The Perl script
    # parses it and uses it as a Perl variable.
    $keys = array('Key_read_requests' => 'gg', 'Key_reads' => 'gh', 'Key_write_requests' => 'gi', 'Key_writes' => 'gj', 'history_list' => 'gk', 'innodb_transactions' => 'gl', 'read_views' => 'gm', 'current_transactions' => 'gn', 'locked_transactions' => 'go', 'active_transactions' => 'gp', 'pool_size' => 'gq', 'free_pages' => 'gr', 'database_pages' => 'gs', 'modified_pages' => 'gt', 'pages_read' => 'gu', 'pages_created' => 'gv', 'pages_written' => 'gw', 'file_fsyncs' => 'gx', 'file_reads' => 'gy', 'file_writes' => 'gz', 'log_writes' => 'hg', 'pending_aio_log_ios' => 'hh', 'pending_aio_sync_ios' => 'hi', 'pending_buf_pool_flushes' => 'hj', 'pending_chkp_writes' => 'hk', 'pending_ibuf_aio_reads' => 'hl', 'pending_log_flushes' => 'hm', 'pending_log_writes' => 'hn', 'pending_normal_aio_reads' => 'ho', 'pending_normal_aio_writes' => 'hp', 'ibuf_inserts' => 'hq', 'ibuf_merged' => 'hr', 'ibuf_merges' => 'hs', 'spin_waits' => 'ht', 'spin_rounds' => 'hu', 'os_waits' => 'hv', 'rows_inserted' => 'hw', 'rows_updated' => 'hx', 'rows_deleted' => 'hy', 'rows_read' => 'hz', 'Table_locks_waited' => 'ig', 'Table_locks_immediate' => 'ih', 'Slow_queries' => 'ii', 'Open_files' => 'ij', 'Open_tables' => 'ik', 'Opened_tables' => 'il', 'innodb_open_files' => 'im', 'open_files_limit' => 'in', 'table_cache' => 'io', 'Aborted_clients' => 'ip', 'Aborted_connects' => 'iq', 'Max_used_connections' => 'ir', 'Slow_launch_threads' => 'is', 'Threads_cached' => 'it', 'Threads_connected' => 'iu', 'Threads_created' => 'iv', 'Threads_running' => 'iw', 'max_connections' => 'ix', 'thread_cache_size' => 'iy', 'Connections' => 'iz', 'slave_running' => 'jg', 'slave_stopped' => 'jh', 'Slave_retried_transactions' => 'ji', 'slave_lag' => 'jj', 'Slave_open_temp_tables' => 'jk', 'Qcache_free_blocks' => 'jl', 'Qcache_free_memory' => 'jm', 'Qcache_hits' => 'jn', 'Qcache_inserts' => 'jo', 'Qcache_lowmem_prunes' => 'jp', 'Qcache_not_cached' => 'jq', 'Qcache_queries_in_cache' => 'jr', 'Qcache_total_blocks' => 'js', 'query_cache_size' => 'jt', 'Questions' => 'ju', 'Com_update' => 'jv', 'Com_insert' => 'jw', 'Com_select' => 'jx', 'Com_delete' => 'jy', 'Com_replace' => 'jz', 'Com_load' => 'kg', 'Com_update_multi' => 'kh', 'Com_insert_select' => 'ki', 'Com_delete_multi' => 'kj', 'Com_replace_select' => 'kk', 'Select_full_join' => 'kl', 'Select_full_range_join' => 'km', 'Select_range' => 'kn', 'Select_range_check' => 'ko', 'Select_scan' => 'kp', 'Sort_merge_passes' => 'kq', 'Sort_range' => 'kr', 'Sort_rows' => 'ks', 'Sort_scan' => 'kt', 'Created_tmp_tables' => 'ku', 'Created_tmp_disk_tables' => 'kv', 'Created_tmp_files' => 'kw', 'Bytes_sent' => 'kx', 'Bytes_received' => 'ky', 'innodb_log_buffer_size' => 'kz', 'unflushed_log' => 'lg', 'log_bytes_flushed' => 'lh', 'log_bytes_written' => 'li', 'relay_log_space' => 'lj', 'binlog_cache_size' => 'lk', 'Binlog_cache_disk_use' => 'll', 'Binlog_cache_use' => 'lm', 'binary_log_space' => 'ln', 'innodb_locked_tables' => 'lo', 'innodb_lock_structs' => 'lp', 'State_closing_tables' => 'lq', 'State_copying_to_tmp_table' => 'lr', 'State_end' => 'ls', 'State_freeing_items' => 'lt', 'State_init' => 'lu', 'State_locked' => 'lv', 'State_login' => 'lw', 'State_preparing' => 'lx', 'State_reading_from_net' => 'ly', 'State_sending_data' => 'lz', 'State_sorting_result' => 'mg', 'State_statistics' => 'mh', 'State_updating' => 'mi', 'State_writing_to_net' => 'mj', 'State_none' => 'mk', 'State_other' => 'ml', 'Handler_commit' => 'mm', 'Handler_delete' => 'mn', 'Handler_discover' => 'mo', 'Handler_prepare' => 'mp', 'Handler_read_first' => 'mq', 'Handler_read_key' => 'mr', 'Handler_read_next' => 'ms', 'Handler_read_prev' => 'mt', 'Handler_read_rnd' => 'mu', 'Handler_read_rnd_next' => 'mv', 'Handler_rollback' => 'mw', 'Handler_savepoint' => 'mx', 'Handler_savepoint_rollback' => 'my', 'Handler_update' => 'mz', 'Handler_write' => 'ng', 'innodb_tables_in_use' => 'nh', 'innodb_lock_wait_secs' => 'ni', 'hash_index_cells_total' => 'nj', 'hash_index_cells_used' => 'nk', 'total_mem_alloc' => 'nl', 'additional_pool_alloc' => 'nm', 'uncheckpointed_bytes' => 'nn', 'ibuf_used_cells' => 'no', 'ibuf_free_cells' => 'np', 'ibuf_cell_count' => 'nq', 'adaptive_hash_memory' => 'nr', 'page_hash_memory' => 'ns', 'dictionary_cache_memory' => 'nt', 'file_system_memory' => 'nu', 'lock_system_memory' => 'nv', 'recovery_system_memory' => 'nw', 'thread_hash_memory' => 'nx', 'innodb_sem_waits' => 'ny', 'innodb_sem_wait_time_ms' => 'nz', 'Key_buf_bytes_unflushed' => 'og', 'Key_buf_bytes_used' => 'oh', 'key_buffer_size' => 'oi', 'Innodb_row_lock_time' => 'oj', 'Innodb_row_lock_waits' => 'ok', 'Query_time_count_00' => 'ol', 'Query_time_count_01' => 'om', 'Query_time_count_02' => 'on', 'Query_time_count_03' => 'oo', 'Query_time_count_04' => 'op', 'Query_time_count_05' => 'oq', 'Query_time_count_06' => 'or', 'Query_time_count_07' => 'os', 'Query_time_count_08' => 'ot', 'Query_time_count_09' => 'ou', 'Query_time_count_10' => 'ov', 'Query_time_count_11' => 'ow', 'Query_time_count_12' => 'ox', 'Query_time_count_13' => 'oy', 'Query_time_total_00' => 'oz', 'Query_time_total_01' => 'pg', 'Query_time_total_02' => 'ph', 'Query_time_total_03' => 'pi', 'Query_time_total_04' => 'pj', 'Query_time_total_05' => 'pk', 'Query_time_total_06' => 'pl', 'Query_time_total_07' => 'pm', 'Query_time_total_08' => 'pn', 'Query_time_total_09' => 'po', 'Query_time_total_10' => 'pp', 'Query_time_total_11' => 'pq', 'Query_time_total_12' => 'pr', 'Query_time_total_13' => 'ps', 'wsrep_replicated_bytes' => 'pt', 'wsrep_received_bytes' => 'pu', 'wsrep_replicated' => 'pv', 'wsrep_received' => 'pw', 'wsrep_local_cert_failures' => 'px', 'wsrep_local_bf_aborts' => 'py', 'wsrep_local_send_queue' => 'pz', 'wsrep_local_recv_queue' => 'qg', 'wsrep_cluster_size' => 'qh', 'wsrep_cert_deps_distance' => 'qi', 'wsrep_apply_window' => 'qj', 'wsrep_commit_window' => 'qk', 'wsrep_flow_control_paused' => 'ql', 'wsrep_flow_control_sent' => 'qm', 'wsrep_flow_control_recv' => 'qn', 'pool_reads' => 'qo', 'pool_read_requests' => 'qp');
    # Return the output.
    $output = array();
    foreach ($keys as $key => $short) {
        # If the value isn't defined, return -1 which is lower than (most graphs')
        # minimum value of 0, so it'll be regarded as a missing value.
        $val = isset($status[$key]) ? $status[$key] : -1;
        $output[] = "{$short}:{$val}";
    }
    $result = implode(' ', $output);
    if ($fp) {
        if (fwrite($fp, $result) === FALSE) {
            die("Can't write '{$cache_file}'");
        }
        fclose($fp);
    }
    return $result;
}
    printf("[020] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
if (!is_object($res = mysqli_store_result($link, MYSQLI_STORE_RESULT_COPY_DATA))) {
    printf("[021] Expecting object, got %s/%s. [%d] %s\n", gettype($res), $res, mysqli_errno($link), mysqli_error($link));
}
/* user conn killed, res associated with conn, fetch from res */
unset($link);
var_dump($res->fetch_assoc());
if (!($link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))) {
    printf("[022] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", $host, $user, $db, $port, $socket);
}
if (!($res = mysqli_real_query($link, "INSERT INTO test(id, label) VALUES (100, 'z')"))) {
    printf("[023] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
mysqli_store_result($link, MYSQLI_STORE_RESULT_COPY_DATA);
if (mysqli_get_server_version($link) > 50000) {
    // let's try to play with stored procedures
    mysqli_real_query($link, 'DROP PROCEDURE IF EXISTS p');
    if (mysqli_real_query($link, 'CREATE PROCEDURE p(OUT ver_param VARCHAR(25)) READS SQL DATA BEGIN SELECT id FROM test WHERE id >= 100 ORDER BY id; SELECT id + 1, label FROM test WHERE id > 0 AND id < 3 ORDER BY id; SELECT VERSION() INTO ver_param;
END;')) {
        mysqli_multi_query($link, "CALL p(@version)");
        do {
            if ($res = $link->store_result(MYSQLI_STORE_RESULT_COPY_DATA)) {
                printf("---\n");
                var_dump($res->fetch_all());
                $res->free();
            } else {
                if ($link->errno) {
                    echo "Store failed: (" . $link->errno . ") " . $link->error;
                }
            }
Пример #10
0
<?php

require_once "connect.inc";
$test_table_name = 'test_mysqli_get_server_version_table_1';
require "table.inc";
/* 5.1.5 -> 50105 -- major_version*10000 + minor_version *100 + sub_version */
/* < 30000 = pre 3.2.3, very unlikely! */
if (!is_int($info = mysqli_get_server_version($link)) || $info < 3 * 10000) {
    printf("[003] Expecting int/any >= 30000, got %s/%s\n", gettype($info), $info);
}
print "done!";
Пример #11
0
 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;
 }
Пример #12
0
/**
 * 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>';
}
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);
Пример #14
0
<?php

require_once "connect.inc";
$db = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
$qry = $db->stmt_init();
$qry->prepare("SELECT REPEAT('a',100000)");
$qry->execute();
$qry->bind_result($text);
$qry->fetch();
if ($text !== str_repeat('a', $IS_MYSQLND || mysqli_get_server_version($db) > 50110 ? 100000 : (mysqli_get_server_version($db) >= 50000 ? 8193 : 8191))) {
    var_dump(strlen($text));
}
echo "Done";
$log_queries_not_using_indexes = false;
mysqli_report(MYSQLI_REPORT_OFF);
mysqli_report(MYSQLI_REPORT_INDEX);
if (!($link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))) {
    printf("[017] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
}
if (mysqli_get_server_version($link) <= 50600) {
    // this might cause a warning - no index used
    if (!($res = @mysqli_query($link, "SHOW VARIABLES LIKE 'log_slow_queries'"))) {
        printf("[018] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
    }
    if (!($row = mysqli_fetch_assoc($res))) {
        printf("[019] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
    }
    $log_slow_query = 'ON' == $row['Value'];
    if (mysqli_get_server_version($link) >= 50111) {
        // this might cause a warning - no index used
        if (!($res = @mysqli_query($link, "SHOW VARIABLES LIKE 'log_queries_not_using_indexes'"))) {
            printf("[020] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
        }
        if (!($row = mysqli_fetch_assoc($res))) {
            printf("[021] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
        }
        $log_queries_not_using_indexes = 'ON' == $row['Value'];
        if ($log_slow_queries && $log_queries_not_using_indexes) {
            for ($i = 100; $i < 20000; $i++) {
                if (!mysqli_query($link, "INSERT INTO test(id, label) VALUES ({$i}, 'z')")) {
                    printf("[022 - %d] [%d] %s\n", $i - 99, mysqli_errno($link), mysqli_error($link));
                }
            }
            // this might cause a warning - no index used
Пример #16
0
 function version()
 {
     if (empty($this->version)) {
         $this->version = mysqli_get_server_version($this->link);
     }
     return $this->version;
 }
Пример #17
0
<?php

require_once "connect.inc";
/*** test mysqli_connect 127.0.0.1 ***/
$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
$stmt = mysqli_prepare($link, "SHOW VARIABLES LIKE 'port'");
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $c1, $c2);
mysqli_stmt_fetch($stmt);
mysqli_stmt_close($stmt);
if (version_compare(PHP_VERSION, '6.0', '==') == 1 && mysqli_get_server_version($link) < 50000) {
    /* variables are binary */
    settype($c1, "unicode");
    settype($c2, "unicode");
}
$test = array($c1, $c2);
var_dump($test);
mysqli_close($link);
print "done!";
Пример #18
0
    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!";
assert(soundex(mysqli_stat($link)) == soundex($mysqli->stat));
printf("mysqli->stat = '%s'/%s ('%s'/%s)\n", $mysqli->stat, gettype($mysqli->stat), mysqli_stat($link), gettype(mysqli_stat($link)));
assert(mysqli_get_host_info($link) === $mysqli->host_info);
printf("mysqli->host_info = '%s'/%s ('%s'/%s)\n", $mysqli->host_info, gettype($mysqli->host_info), mysqli_get_host_info($link), gettype(mysqli_get_host_info($link)));
/* note that the data types are different */
assert(mysqli_info($link) == $mysqli->info);
printf("mysqli->info = '%s'/%s ('%s'/%s)\n", $mysqli->info, gettype($mysqli->info), mysqli_info($link), gettype(mysqli_info($link)));
assert(mysqli_thread_id($link) > $mysqli->thread_id);
assert(gettype($mysqli->thread_id) == gettype(mysqli_thread_id($link)));
printf("mysqli->thread_id = '%s'/%s ('%s'/%s)\n", $mysqli->thread_id, gettype($mysqli->thread_id), mysqli_thread_id($link), gettype(mysqli_thread_id($link)));
assert(mysqli_get_proto_info($link) === $mysqli->protocol_version);
printf("mysqli->protocol_version = '%s'/%s ('%s'/%s)\n", $mysqli->protocol_version, gettype($mysqli->protocol_version), mysqli_get_proto_info($link), gettype(mysqli_get_proto_info($link)));
assert(mysqli_get_server_info($link) === $mysqli->server_info);
printf("mysqli->server_info = '%s'/%s ('%s'/%s)\n", $mysqli->server_info, gettype($mysqli->server_info), mysqli_get_server_info($link), gettype(mysqli_get_server_info($link)));
assert(mysqli_get_server_version($link) === $mysqli->server_version);
printf("mysqli->server_version = '%s'/%s ('%s'/%s)\n", $mysqli->server_version, gettype($mysqli->server_version), mysqli_get_server_version($link), gettype(mysqli_get_server_version($link)));
assert(mysqli_warning_count($link) === $mysqli->warning_count);
printf("mysqli->warning_count = '%s'/%s ('%s'/%s)\n", $mysqli->warning_count, gettype($mysqli->warning_count), mysqli_warning_count($link), gettype(mysqli_warning_count($link)));
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);
$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
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()));
Пример #20
0
 public function version()
 {
     if (!empty($this->connect)) {
         return mysqli_get_server_version($this->connect);
     } else {
         return false;
     }
 }
Пример #21
0
<?php
Пример #22
0
<?php

require_once "connect.inc";
/*** test mysqli_connect 127.0.0.1 ***/
$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
$stmt = mysqli_prepare($link, "SHOW VARIABLES LIKE 'port'");
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $c1, $c2);
mysqli_stmt_fetch($stmt);
mysqli_stmt_close($stmt);
if (version_compare(PHP_VERSION, '5.9.9', '>') == 1 && mysqli_get_server_version($link) < 50000) {
    /* variables are binary */
    settype($c1, "unicode");
    settype($c2, "unicode");
}
$test = array($c1, $c2);
var_dump($test);
mysqli_close($link);
print "done!";
Пример #23
0
<?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];
}
Пример #24
0
<?php

require_once "connect.inc";
/*** test mysqli_connect 127.0.0.1 ***/
$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
$i = mysqli_get_server_version($link);
$test = $i / $i;
var_dump($test);
mysqli_close($link);
print "done!";
func_mysqli_stmt_bind_datatype($link, $engine, "s", "TINYTEXT", "a", 760);
func_mysqli_stmt_bind_datatype($link, $engine, "s", "TINYTEXT NOT NULL", "a", 770);
func_mysqli_stmt_bind_datatype($link, $engine, "s", "TINYTEXT", NULL, 780);
// Note: you cannot insert any blob values this way. But you can check the API at least partly this way
// Extra BLOB tests are in mysqli_stmt_send_long()
func_mysqli_stmt_bind_datatype($link, $engine, "b", "BLOB", "", 790);
func_mysqli_stmt_bind_datatype($link, $engine, "b", "TEXT", "", 800);
func_mysqli_stmt_bind_datatype($link, $engine, "b", "MEDIUMBLOB", "", 810);
func_mysqli_stmt_bind_datatype($link, $engine, "b", "MEDIUMTEXT", "", 820);
func_mysqli_stmt_bind_datatype($link, $engine, "b", "LONGBLOB", "", 830);
func_mysqli_stmt_bind_datatype($link, $engine, "b", "LONGTEXT", "", 840);
func_mysqli_stmt_bind_datatype($link, $engine, "s", "ENUM('a', 'b')", "a", 850);
func_mysqli_stmt_bind_datatype($link, $engine, "s", "ENUM('a', 'b')", NULL, 860);
func_mysqli_stmt_bind_datatype($link, $engine, "s", "SET('a', 'b')", "a", 870);
func_mysqli_stmt_bind_datatype($link, $engine, "s", "SET('a', 'b')", NULL, 880);
if (mysqli_get_server_version($link) >= 50600) {
    func_mysqli_stmt_bind_datatype($link, $engine, "s", "TIME", "13:27:34.123456", 890, "13:27:34");
}
$stmt = mysqli_stmt_init($link);
if (!mysqli_stmt_prepare($stmt, "INSERT INTO test(id, label) VALUES (?, ?)")) {
    printf("[2000] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
}
$id = null;
$label = null;
if (true !== ($tmp = mysqli_stmt_bind_param($stmt, "is", $id, $label))) {
    printf("[2001] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
}
mysqli_stmt_execute($stmt);
if (true !== ($tmp = mysqli_stmt_bind_param($stmt, "is", $id, $label))) {
    printf("[2002] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
}
Пример #26
0
 static function sql_version()
 {
     $version = "";
     if (SETUP_DB_TYPE == "mysqli") {
         $version = floor(mysqli_get_server_version(sys::$db) / 100);
     } else {
         if (SETUP_DB_TYPE == "pgsql") {
             $version = sql_fetch_one("show server_version");
             $version = (int) substr(str_replace(".", "", $version["server_version"]), 0, 3);
         } else {
             if (SETUP_DB_TYPE == "sqlite") {
                 $version = sys::$db->getAttribute(PDO::ATTR_SERVER_VERSION);
                 $version = (int) substr(str_replace(".", "", $version), 0, 3);
             }
         }
     }
     if (strlen($version) < 3) {
         $version .= "0";
     }
     return $version;
 }
Пример #27
0
 /**
  * return version of mysql used on server
  * @return [type] [description]
  */
 public static function version()
 {
     // mysqli_get_client_info();
     // mysqli_get_client_version();
     return mysqli_get_server_version(self::$link);
 }
Пример #28
0
            $version = mysqli_get_server_version($link);
            if ($version <= 50114 && $version > 50100 || $version == 50200) {
                // TODO - check exact version!
                $expected_flags = trim(str_replace('UNSIGNED', '', $expected_flags));
            }
        default:
            break;
    }
    list($missing_flags, $unexpected_flags, $flags_found) = checkFlags($field->flags, $expected_flags, $flags);
    if ($unexpected_flags) {
        printf("[006] Found unexpected flags '%s' for %s, found '%s' with MySQL %s'\n", $unexpected_flags, $column_def, $flags_found, mysqli_get_server_version($link));
    }
    if ($missing_flags) {
        printf("[007] The flags '%s' have not been reported for %s, found '%s'\n", $missing_flags, $column_def, $flags_found);
        var_dump($create);
        var_dump(mysqli_get_server_version($link));
        die($missing_flags);
    }
    mysqli_free_result($res);
}
if (!mysqli_query($link, 'DROP TABLE IF EXISTS test_mysqli_fetch_field_flags_table_1')) {
    printf("[008] %s [%d] %s\n", $column_def, mysqli_errno($link), mysqli_error($link));
    continue;
}
$column_def = array('col1 CHAR(1)', 'col2 CHAR(2)', 'INDEX idx_col1_col2(col1, col2)');
$expected_flags = array('col1' => 'MULTIPLE_KEY PART_KEY', 'col2' => 'PART_KEY');
$create = 'CREATE TABLE test_mysqli_fetch_field_flags_table_1(id INT, ';
foreach ($column_def as $k => $v) {
    $create .= sprintf('%s, ', $v);
}
$create = sprintf('%s)', substr($create, 0, -2));
Пример #29
0
 /**
  * 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('&lt;', '&gt;'), $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;
     }
 }
if ($strict_on) {
    $tmp = ob_get_contents();
    ob_end_clean();
    if (!preg_match('@Strict Standards: mysqli_next_result\\(\\): There is no next result set@ismU', $tmp)) {
        printf("[008] Strict Standards warning missing\n");
    } else {
        $tmp = trim(preg_replace('@Strict Standards: mysqli_next_result\\(\\).*on line \\d+@ism', '', $tmp));
    }
    print trim($tmp) . "\n";
}
if (!mysqli_multi_query($link, "SELECT 1 AS a; SELECT 1 AS a, 2 AS b; SELECT id FROM test ORDER BY id LIMIT 3")) {
    printf("[009] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
print "[010]\n";
$i = 1;
if (mysqli_get_server_version($link) > 41000 && !($ret = mysqli_more_results($link))) {
    printf("[011] Expecting boolean/true, got %s/%s\n", gettype($ret), $ret);
}
if ($strict_on) {
    ob_start();
}
do {
    $res = mysqli_use_result($link);
    // NOTE: if you use mysqli_use_result() with mysqli_more_results() or any other info function,
    // you must fetch all rows before you can loop to the next result set!
    // See also the MySQL Reference Manual: mysql_use_result()
    while ($row = mysqli_fetch_array($res)) {
    }
    mysqli_free_result($res);
    if (mysqli_more_results($link)) {
        printf("%d\n", $i++);