示例#1
0
 /**
  * mysql_connect();
  * Connect and select database.
  * @param string The database host. (default 'localhost')
  * @param string The database username. (default 'root')
  * @param string The database user password. (default '')
  * @return boolean true if new connection, false if not. (default false)
  * @param boolean true if persistent connection, false if not. (default false)
  * @param string The database name.
  * @return string The database table prefix. (default '_')
  */
 function connect($db_host = 'localhost', $db_username = '******', $db_password = '', $new_link_id = false, $pconnect = false, $db_name, $table_prefix = '_')
 {
     // Construct the username and tables prefix.
     $this->db_username = $db_username;
     $this->db_name = $db_name;
     $this->tbl_pre = $table_prefix;
     // Connect to the database.
     if ($pconnect) {
         $this->link_id = @mysql_pconnect($db_host, $db_username, $db_password);
     } else {
         $this->link_id = @mysql_connect($db_host, $db_username, $db_password, $new_link_id);
     }
     if (!$this->link_id) {
         $this->db_error('connect', $db_host);
     }
     // Valid db charset and set custom charset if it defined.
     // Select db.
     if ($this->link_id) {
         $this->valid_charset = @mysql_client_encoding($this->link_id);
         if (defined('DB_CHARSET') && DB_CHARSET != '') {
             $this->query("SET NAMES " . DB_CHARSET);
         }
         if (!@mysql_select_db($this->db_name, $this->link_id)) {
             $this->db_error('select', '');
         } else {
             return $this->link_id;
         }
     }
     unset($db_host, $db_username, $db_password, $new_link_id, $pconnect, $db_name, $table_prefix);
 }
function db_get_encoding($error_checking = true)
{
    global $MySQL;
    $res = mysql_client_encoding($MySQL->link);
    if ($error_checking && !$res) {
        genMySQLErr('Database get encoding error');
    }
    return $res;
}
示例#3
0
 function GetCharSet()
 {
     if (function_exists('mysql_client_encoding')) {
         $this->charSet = @mysql_client_encoding($this->_connectionID);
     }
     if (!$this->charSet) {
         return false;
     } else {
         return $this->charSet;
     }
 }
 private function _doError()
 {
     if ($this->database->getAdapter()->hasError()) {
         $e = $this->database->getAdapter()->getError();
         $m = array();
         $m[] = 'Database Error : ' . $e->getCode();
         $m[] = 'Message: ' . $e->getMessage();
         $m[] = 'Query: ' . $e->getQuery();
         $m[] = 'Encoding: ' . mysql_client_encoding();
         trigger_error(implode('<br />', $m));
     }
 }
示例#5
0
 function connect()
 {
     if ($GLOBALS['db_link']) {
         return;
     }
     profile_point('H2Database:connect() start');
     $GLOBALS['db_link'] = mysql_pconnect(cfg('db/host'), cfg('db/user'), cfg('db/password')) or critical('The database connection to server ' . cfg('db/user') . '@' . cfg('db/host') . ' could not be established (code: ' . @mysql_error($GLOBALS['db_link']) . ')');
     mysql_select_db(cfg('db/database'), $GLOBALS['db_link']) or critical('The database connection to database ' . cfg('db/database') . ' on ' . cfg('db/user') . '@' . cfg('db/host') . ' could not be established. (code: ' . @mysql_error($GLOBALS['db_link']) . ')');
     if (mysql_client_encoding() != 'utf8') {
         mysql_set_charset('utf8');
     }
     profile_point('H2Database:connect() done');
 }
示例#6
0
 protected function lazyConnect()
 {
     $this->connection = mysql_connect($this->host, $this->user, $this->pass);
     if (!$this->connection) {
         throw new MySquirrelException_ConnectionError('Could not connect to ' . $this->host . '.');
     }
     $select_db = mysql_select_db($this->database, $this->connection);
     if (!$select_db) {
         throw new MySquirrelException_ConnectionError('Could not select database ' . $this->database . '.');
     }
     // Attempt to change the character set if necessary.
     if ($this->charset !== false) {
         if (function_exists('mysql_set_charset')) {
             $select_charset = mysql_set_charset($this->charset, $this->connection);
         } elseif (mysql_client_encoding($this->connection) !== $this->charset) {
             $msg = 'Changing the character set requires MySQL 5.0.7 or higher, and PHP 5.2.3 or higher. ';
             $msg .= 'Your database\'s default character set is ' . mysql_client_encoding($this->connection) . '.';
             throw new MySquirrelException_CharacterSetError($msg);
         }
     }
 }
示例#7
0
文件: Debug.php 项目: ragi79/Textcube
function __tcSqlLogEnd($result, $cachedResult = 0)
{
    global $__tcSqlLog, $__tcSqlQueryBeginTime, $__tcSqlLogCount, $__tcPageStartTime;
    static $client_encoding = '';
    $tcSqlQueryEndTime = explode(' ', microtime());
    $elapsed = $tcSqlQueryEndTime[1] - $__tcSqlQueryBeginTime[1] + ($tcSqlQueryEndTime[0] - $__tcSqlQueryBeginTime[0]);
    if (!$client_encoding) {
        $client_encoding = str_replace('_', '-', mysql_client_encoding());
    }
    if ($client_encoding != 'utf8' && function_exists('iconv')) {
        $__tcSqlLog[$__tcSqlLogCount]['error'] = iconv($client_encoding, 'utf-8', mysql_error());
    } else {
        $__tcSqlLog[$__tcSqlLogCount]['error'] = mysql_error();
    }
    $__tcSqlLog[$__tcSqlLogCount]['errno'] = mysql_errno();
    if ($cachedResult == 0) {
        $__tcSqlLog[$__tcSqlLogCount]['elapsed'] = ceil($elapsed * 10000) / 10;
    } else {
        $__tcSqlLog[$__tcSqlLogCount]['elapsed'] = 0;
    }
    $__tcSqlLog[$__tcSqlLogCount]['elapsed'] = sprintf("%4.1f", $__tcSqlLog[$__tcSqlLogCount]['elapsed']);
    $__tcSqlLog[$__tcSqlLogCount]['cached'] = $cachedResult;
    $__tcSqlLog[$__tcSqlLogCount]['rows'] = 0;
    $__tcSqlLog[$__tcSqlLogCount]['endtime'] = $tcSqlQueryEndTime[1] - $__tcPageStartTime[1] + ($tcSqlQueryEndTime[0] - $__tcPageStartTime[0]);
    $__tcSqlLog[$__tcSqlLogCount]['endtime'] = sprintf("%4.1f", ceil($__tcSqlLog[$__tcSqlLogCount]['endtime'] * 10000) / 10);
    if (!$cachedResult && mysql_errno() == 0) {
        switch (strtolower(substr($__tcSqlLog[$__tcSqlLogCount]['sql'], 0, 6))) {
            case 'select':
                $__tcSqlLog[$__tcSqlLogCount]['rows'] = mysql_num_rows($result);
                break;
            case 'insert':
            case 'delete':
            case 'update':
                $__tcSqlLog[$__tcSqlLogCount]['rows'] = mysql_affected_rows();
                break;
        }
    }
    $__tcSqlLogCount++;
    $__tcSqlQueryBeginTime = 0;
}
示例#8
0
 function Connect($host, $user, $pass)
 {
     error_reporting(null);
     global $CONFIG_mysql_charset;
     $this->link = mysql_connect($host, $user, $pass);
     $GLOBALS['link'] = $this->link;
     if (!$this->link) {
         $this->error_found("01");
     }
     switch ($CONFIG_mysql_charset) {
         case auto:
             $this->charset = mysql_client_encoding($this->link);
             mysql_query("SET NAMES " . $this->charset . "");
             break;
         case disable:
             break;
         default:
             mysql_query("SET NAMES " . $CONFIG_mysql_charset . "");
             break;
     }
     return true;
 }
示例#9
0
 function connect($host = NULL, $user = NULL, $password = NULL, $port = "3306")
 {
     if ($host) {
         $this->_connection['host'] = $host;
     }
     if ($user) {
         $this->_connection['user'] = $user;
     }
     if ($password) {
         $this->_connection['pass'] = $password;
     }
     if ($port) {
         $this->_connection['port'] = $port;
     }
     $this->_connection['id'] = @mysql_connect($this->_connection['host'] . ":" . $this->_connection['port'], $this->_connection['user'], $this->_connection['pass']);
     if (!$this->isConnected()) {
         $this->__error("Error establishing database connection: Check details");
         return false;
     }
     $this->_client_info = mysql_get_client_info();
     $this->_client_encoding = mysql_client_encoding($this->_connection['id']);
     return true;
 }
示例#10
0
    echo "</script>";
}
// include the default language
require_once WB_PATH . '/modules/foldergallery/languages/EN.php';
// check if module language file exists for the language set by the user (e.g. DE, EN)
if (file_exists(WB_PATH . '/modules/foldergallery/languages/' . LANGUAGE . '.php')) {
    require_once WB_PATH . '/modules/foldergallery/languages/' . LANGUAGE . '.php';
}
// Files includen
require_once WB_PATH . '/modules/foldergallery/info.php';
require_once WB_PATH . '/modules/foldergallery/admin/scripts/backend.functions.php';
require_once WB_PATH . '/modules/foldergallery/class/class.upload.php';
require_once WB_PATH . '/modules/foldergallery/class/validator.php';
require_once WB_PATH . '/modules/foldergallery/class/DirectoryHandler.Class.php';
//  Set the mySQL encoding to utf8
$oldMysqlEncoding = mysql_client_encoding();
mysql_set_charset('utf8', $database->db_handle);
$settings = getSettings($section_id);
$root_dir = $settings['root_dir'];
//Chio
if (isset($_GET['cat_id']) && is_numeric($_GET['cat_id'])) {
    $cat_id = $_GET['cat_id'];
} else {
    $error['no_cat_id'] = 1;
    $admin->print_error('lost cat', ADMIN_URL . '/pages/modify.php?page_id=' . $page_id . '&section_id=' . $section_id);
    die;
}
// Kategorie Infos aus der DB holen
$sql = 'SELECT * FROM ' . TABLE_PREFIX . 'mod_foldergallery_categories WHERE id=' . $cat_id . ' LIMIT 1;';
$query = $database->query($sql);
$categorie = $query->fetchRow();
示例#11
0
function doDiagnostics()
{
    global $prefs, $files, $txpcfg, $step;
    extract(get_prefs());
    $urlparts = parse_url(hu);
    $mydomain = $urlparts['host'];
    $server_software = @$_SERVER['SERVER_SOFTWARE'] || @$_SERVER['HTTP_HOST'] ? @$_SERVER['SERVER_SOFTWARE'] ? @$_SERVER['SERVER_SOFTWARE'] : $_SERVER['HTTP_HOST'] : '';
    $is_apache = ($server_software and stristr($server_software, 'Apache')) or is_callable('apache_get_version');
    $real_doc_root = isset($_SERVER['DOCUMENT_ROOT']) ? realpath($_SERVER['DOCUMENT_ROOT']) : '';
    // ini_get() returns string values passed via php_value as a string, not boolean
    $is_register_globals = (strcasecmp(ini_get('register_globals'), 'on') === 0 or ini_get('register_globals') === '1');
    $fail = array('php_version_4_3_0_required' => (!is_callable('version_compare') or version_compare(PHP_VERSION, '4.3.0', '<')) ? gTxt('php_version_4_3_0_required') : '', 'path_to_site_missing' => !isset($path_to_site) ? gTxt('path_to_site_missing') : '', 'dns_lookup_fails' => @gethostbyname($mydomain) == $mydomain ? gTxt('dns_lookup_fails') . cs . $mydomain : '', 'path_to_site_inacc' => !@is_dir($path_to_site) ? gTxt('path_to_site_inacc') . cs . $path_to_site : '', 'site_trailing_slash' => rtrim($siteurl, '/') != $siteurl ? gTxt('site_trailing_slash') . cs . $path_to_site : '', 'index_inaccessible' => (!@is_file($path_to_site . "/index.php") or !@is_readable($path_to_site . "/index.php")) ? "{$path_to_site}/index.php " . gTxt('is_inaccessible') : '', 'dir_not_writable' => trim((!@is_writable($path_to_site . '/' . $img_dir) ? str_replace('{dirtype}', gTxt('img_dir'), gTxt('dir_not_writable')) . ": {$path_to_site}/{$img_dir}\r\n" : '') . (!@is_writable($file_base_path) ? str_replace('{dirtype}', gTxt('file_base_path'), gTxt('dir_not_writable')) . ": {$file_base_path}\r\n" : '') . (!@is_writable($tempdir) ? str_replace('{dirtype}', gTxt('tempdir'), gTxt('dir_not_writable')) . ": {$tempdir}\r\n" : '')), 'cleanurl_only_apache' => ($permlink_mode != 'messy' and !$is_apache) ? gTxt('cleanurl_only_apache') : '', 'htaccess_missing' => ($permlink_mode != 'messy' and !@is_readable($path_to_site . '/.htaccess')) ? gTxt('htaccess_missing') : '', 'mod_rewrite_missing' => ($permlink_mode != 'messy' and is_callable('apache_get_modules') and !apache_module('mod_rewrite')) ? gTxt('mod_rewrite_missing') : '', 'file_uploads_disabled' => !ini_get('file_uploads') ? gTxt('file_uploads_disabled') : '', 'setup_still_exists' => @is_dir(txpath . DS . 'setup') ? txpath . DS . "setup" . DS . ' ' . gTxt('still_exists') : '', 'no_temp_dir' => empty($tempdir) ? gTxt('no_temp_dir') : '', 'warn_mail_unavailable' => !is_callable('mail') ? gTxt('warn_mail_unavailable') : '', 'warn_register_globals_or_update' => $is_register_globals && (version_compare(phpversion(), '4.4.0', '<=') or version_compare(phpversion(), '5.0.0', '>=') and version_compare(phpversion(), '5.0.5', '<=')) ? gTxt('warn_register_globals_or_update') : '');
    if ($permlink_mode != 'messy') {
        $rs = safe_column("name", "txp_section", "1");
        foreach ($rs as $name) {
            if ($name and @file_exists($path_to_site . '/' . $name)) {
                $fail['old_placeholder_exists'] = gTxt('old_placeholder') . ": {$path_to_site}/{$name}";
            }
        }
    }
    $missing = array();
    foreach ($files as $f) {
        if (!is_readable(txpath . $f)) {
            $missing[] = txpath . $f;
        }
    }
    if ($missing) {
        $fail['missing_files'] = gTxt('missing_files') . cs . join(', ', $missing);
    }
    foreach ($fail as $k => $v) {
        if (empty($v)) {
            unset($fail[$k]);
        }
    }
    # Find the highest revision number
    $file_revs = array();
    $rev = 0;
    foreach ($files as $f) {
        $lines = @file(txpath . $f);
        if ($lines) {
            foreach ($lines as $line) {
                if (preg_match('/^\\$' . 'LastChangedRevision: (\\w+) \\$/', $line, $match)) {
                    $file_revs[$f] = $match[1];
                    if (intval($match[1]) > $rev) {
                        $rev = intval($match[1]);
                    }
                }
            }
        }
    }
    # Check revs & md5 against stable release, if possible
    $dev_files = $old_files = $modified_files = array();
    if ($cs = @file(txpath . '/checksums.txt')) {
        foreach ($cs as $c) {
            if (preg_match('@^(\\S+): r?(\\S+) \\((.*)\\)$@', trim($c), $m)) {
                list(, $file, $r, $md5) = $m;
                if (!empty($file_revs[$file]) and $r and $file_revs[$file] < $r) {
                    $old_files[] = $file;
                } elseif (!empty($file_revs[$file]) and $r and $file_revs[$file] > $r) {
                    $dev_files[] = $file;
                } elseif (@is_readable(txpath . $file) and ($sum = md5_file(txpath . $file)) != $md5) {
                    $modified_files[] = $file;
                }
            }
        }
    }
    # files that haven't been updated
    if ($old_files) {
        $fail['old_files'] = gTxt('old_files') . cs . n . t . join(', ' . n . t, $old_files);
    }
    # files that don't match their checksums
    if ($modified_files) {
        $fail['modified_files'] = gTxt('modified_files') . cs . n . t . join(', ' . n . t, $modified_files);
    }
    # running development code in live mode is not recommended
    if ($dev_files and $production_status == 'live') {
        $fail['dev_version_live'] = gTxt('dev_version_live') . cs . n . t . join(', ' . n . t, $dev_files);
    }
    # anything might break if arbitrary functions are disabled
    if (ini_get('disable_functions')) {
        $disabled_funcs = array_map('trim', explode(',', ini_get('disable_functions')));
        # commonly disabled functions that we don't need
        $disabled_funcs = array_diff($disabled_funcs, array('imagefilltoborder', 'exec', 'system', 'dl', 'passthru', 'chown', 'shell_exec', 'popen', 'proc_open'));
        if ($disabled_funcs) {
            $fail['some_php_functions_disabled'] = gTxt('some_php_functions_disabled') . cs . join(', ', $disabled_funcs);
        }
    }
    # not sure about this one
    #if (strncmp(php_sapi_name(), 'cgi', 3) == 0 and ini_get('cgi.rfc2616_headers'))
    #	$fail['cgi_header_config'] = gTxt('cgi_header_config');
    $guess_site_url = $_SERVER['HTTP_HOST'] . preg_replace('#[/\\\\]$#', '', dirname(dirname($_SERVER['SCRIPT_NAME'])));
    if ($siteurl and strip_prefix($siteurl, 'www.') != strip_prefix($guess_site_url, 'www.')) {
        $fail['site_url_mismatch'] = gTxt('site_url_mismatch') . cs . $guess_site_url;
    }
    # test clean URL server vars
    if (hu) {
        if (ini_get('allow_url_fopen') and $permlink_mode != 'messy') {
            $s = md5(uniqid(rand(), true));
            $pretext_data = @file(hu . $s . '/?txpcleantest=1');
            if ($pretext_data) {
                $pretext_req = trim(@$pretext_data[0]);
                if ($pretext_req != md5('/' . $s . '/?txpcleantest=1')) {
                    $fail['clean_url_data_failed'] = gTxt('clean_url_data_failed') . cs . htmlspecialchars($pretext_req);
                }
            } else {
                $fail['clean_url_test_failed'] = gTxt('clean_url_test_failed');
            }
        }
    }
    if ($tables = list_txp_tables()) {
        $table_errors = check_tables($tables);
        if ($table_errors) {
            $fail['mysql_table_errors'] = gTxt('mysql_table_errors') . cs . n . t . join(', ' . n . t, $table_errors);
        }
    }
    $active_plugins = array();
    if ($rows = safe_rows('name, version, code_md5, md5(code) as md5', 'txp_plugin', 'status > 0')) {
        foreach ($rows as $row) {
            $n = $row['name'] . '-' . $row['version'];
            if (strtolower($row['md5']) != strtolower($row['code_md5'])) {
                $n .= 'm';
            }
            $active_plugins[] = $n;
        }
    }
    // check GD info
    if (function_exists('gd_info')) {
        $gd_info = gd_info();
        $gd_support = array();
        if ($gd_info['GIF Create Support']) {
            $gd_support[] = 'GIF';
        }
        if ($gd_info['JPG Support']) {
            $gd_support[] = 'JPG';
        }
        if ($gd_info['PNG Support']) {
            $gd_support[] = 'PNG';
        }
        if ($gd_support) {
            $gd_support = join(', ', $gd_support);
        } else {
            $gd_support = gTxt('none');
        }
        $gd = gTxt('gd_info', array('{version}' => $gd_info['GD Version'], '{supported}' => $gd_support));
    } else {
        $gd = gTxt('gd_unavailable');
    }
    if (realpath($prefs['tempdir']) == realpath($prefs['plugin_cache_dir'])) {
        $fail['tmp_plugin_paths_match'] = gTxt('tmp_plugin_paths_match');
    }
    echo pagetop(gTxt('tab_diagnostics'), ''), startTable('list'), tr(td(hed(gTxt('preflight_check'), 1)));
    if ($fail) {
        foreach ($fail as $help => $message) {
            echo tr(tda(nl2br($message) . sp . popHelp($help), ' class="not-ok"'));
        }
    } else {
        echo tr(tda(gTxt('all_checks_passed'), ' class="ok"'));
    }
    echo tr(td(hed(gTxt('diagnostic_info'), 1)));
    $fmt_date = '%Y-%m-%d %H:%M:%S';
    $out = array('<textarea cols="78" rows="18" readonly="readonly" style="width: 500px; height: 300px;">', gTxt('txp_version') . cs . txp_version . ' (' . ($rev ? 'r' . $rev : 'unknown revision') . ')' . n, gTxt('last_update') . cs . gmstrftime($fmt_date, $dbupdatetime) . '/' . gmstrftime($fmt_date, @filemtime(txpath . '/update/_update.php')) . n, gTxt('document_root') . cs . @$_SERVER['DOCUMENT_ROOT'] . ($real_doc_root != @$_SERVER['DOCUMENT_ROOT'] ? ' (' . $real_doc_root . ')' : '') . n, '$path_to_site' . cs . $path_to_site . n, gTxt('txp_path') . cs . txpath . n, gTxt('permlink_mode') . cs . $permlink_mode . n, ini_get('open_basedir') ? 'open_basedir: ' . ini_get('open_basedir') . n : '', ini_get('upload_tmp_dir') ? 'upload_tmp_dir: ' . ini_get('upload_tmp_dir') . n : '', gTxt('tempdir') . cs . $tempdir . n, gTxt('web_domain') . cs . $siteurl . n, getenv('TZ') ? 'TZ: ' . getenv('TZ') . n : '', gTxt('php_version') . cs . phpversion() . n, $is_register_globals ? gTxt('register_globals') . cs . $is_register_globals . n : '', gTxt('gd_library') . cs . $gd . n, gTxt('server_time') . cs . strftime('%Y-%m-%d %H:%M:%S') . n, 'MySQL' . cs . mysql_get_server_info() . n, gTxt('locale') . cs . $locale . n, isset($_SERVER['SERVER_SOFTWARE']) ? gTxt('server') . cs . $_SERVER['SERVER_SOFTWARE'] . n : '', is_callable('apache_get_version') ? gTxt('apache_version') . cs . apache_get_version() . n : '', gTxt('php_sapi_mode') . cs . PHP_SAPI . n, gTxt('rfc2616_headers') . cs . ini_get('cgi.rfc2616_headers') . n, gTxt('os_version') . cs . php_uname('s') . ' ' . php_uname('r') . n, $active_plugins ? gTxt('active_plugins') . cs . join(', ', $active_plugins) . n : '', $fail ? n . gTxt('preflight_check') . cs . n . ln . join("\n", $fail) . n . ln : '', is_readable($path_to_site . '/.htaccess') ? n . gTxt('htaccess_contents') . cs . n . ln . htmlspecialchars(join('', file($path_to_site . '/.htaccess'))) . n . ln : '');
    if ($step == 'high') {
        $mysql_client_encoding = is_callable('mysql_client_encoding') ? mysql_client_encoding() : '-';
        $out[] = n . 'Charset (default/config)' . cs . $mysql_client_encoding . '/' . @$txpcfg['dbcharset'] . n;
        $result = safe_query("SHOW variables like 'character_se%'");
        while ($row = mysql_fetch_row($result)) {
            $out[] = $row[0] . cs . $row[1] . n;
            if ($row[0] == 'character_set_connection') {
                $conn_char = $row[1];
            }
        }
        $table_names = array(PFX . 'textpattern');
        $result = safe_query("SHOW TABLES LIKE '" . PFX . "txp\\_%'");
        while ($row = mysql_fetch_row($result)) {
            $table_names[] = $row[0];
        }
        $table_msg = array();
        foreach ($table_names as $table) {
            $ctr = safe_query("SHOW CREATE TABLE " . $table . "");
            if (!$ctr) {
                unset($table_names[$table]);
                continue;
            }
            $ctcharset = preg_replace('#^CREATE TABLE.*SET=([^ ]+)[^)]*$#is', '\\1', mysql_result($ctr, 0, 'Create Table'));
            if (isset($conn_char) && !stristr($ctcharset, 'CREATE') && $conn_char != $ctcharset) {
                $table_msg[] = "{$table} is {$ctcharset}";
            }
            $ctr = safe_query("CHECK TABLE " . $table);
            if (in_array(mysql_result($ctr, 0, 'Msg_type'), array('error', 'warning'))) {
                $table_msg[] = $table . cs . mysql_result($ctr, 0, 'Msg_Text');
            }
        }
        if ($table_msg == array()) {
            $table_msg = count($table_names) < 18 ? array('-') : array('OK');
        }
        $out[] = count($table_names) . ' Tables' . cs . implode(', ', $table_msg) . n;
        $extns = get_loaded_extensions();
        $extv = array();
        foreach ($extns as $e) {
            $extv[] = $e . (phpversion($e) ? '/' . phpversion($e) : '');
        }
        $out[] = n . gTxt('php_extensions') . cs . join(', ', $extv) . n;
        if (is_callable('apache_get_modules')) {
            $out[] = n . gTxt('apache_modules') . cs . join(', ', apache_get_modules()) . n;
        }
        if (@is_array($pretext_data) and count($pretext_data) > 1) {
            $out[] = n . gTxt('pretext_data') . cs . htmlspecialchars(join('', array_slice($pretext_data, 1, 20))) . n;
        }
        $out[] = n;
        foreach ($files as $f) {
            $rev = '';
            $checksum = '';
            if (is_callable('md5_file')) {
                $checksum = md5_file(txpath . $f);
            }
            if (isset($file_revs[$f])) {
                $rev = $file_revs[$f];
            }
            $out[] = "{$f}" . cs . ($rev ? "r" . $rev : gTxt('unknown')) . ' (' . ($checksum ? $checksum : gTxt('unknown')) . ')' . n;
        }
    }
    $out[] = '</textarea>' . br;
    $dets = array('low' => gTxt('low'), 'high' => gTxt('high'));
    $out[] = form(eInput('diag') . n . gTxt('detail') . cs . selectInput('step', $dets, $step, 0, 1));
    echo tr(td(join('', $out))), endTable();
}
 /**
  * get the used character set.
  * if you didnt manually selected one, the one chosen on the server will
  * be returned
  *
  * @access public
  * @return string
  */
 public function getCharSet()
 {
     if ($this->isConnected()) {
         return mysql_client_encoding($this->_connection);
     } else {
         return $this->dbCharSet;
     }
 }
Return Values

Returns the default character set name for the current connection. 
*/
require 'MySQLConverterTool/UnitTests/Converter/TestCode/config.php';
$con = mysql_connect($host, $user, $pass);
if (!$con) {
    printf("FAILURE: [%d] %s\n", mysql_errno(), mysql_error());
} else {
    print "SUCCESS: connect\n";
}
if (!mysql_select_db($db, $con)) {
    printf("FAILURE: [%d] %s\n", mysql_errno($con), mysql_error($con));
}
$encoding_default = mysql_client_encoding();
$encoding_con = mysql_client_encoding($con);
if ($encoding_con != $encoding_default) {
    printf("FAILURE: different client encodings reported, [%d] %s\n", mysql_errno($con), mysql_error($con));
} else {
    if (!is_string($encoding_con)) {
        printf("FAILURE: no string returned, [%d] %s\n", mysql_errno($con), mysql_error($con));
    }
}
mysql_close($con);
?>
--EXPECT-EXT/MYSQL-OUTPUT--
SUCCESS: connect

--EXPECT-EXT/MYSQL-PHP-ERRORS--
--EXPECT-EXT/MYSQLI-OUTPUT--
SUCCESS: connect
 function client_encoding()
 {
     return mysql_client_encoding($this->connect_id);
 }
示例#15
0
 /**
  * Gets or sets the encoding for the connection.
  *
  * @param $encoding
  * @return mixed If setting the encoding; returns true on success, else false.
  *         When getting, returns the encoding.
  */
 public function encoding($encoding = null)
 {
     $encodingMap = array('UTF-8' => 'utf8');
     if (empty($encoding)) {
         $encoding = mysql_client_encoding($this->connection);
         return ($key = array_search($encoding, $encodingMap)) ? $key : $encoding;
     }
     $encoding = isset($encodingMap[$encoding]) ? $encodingMap[$encoding] : $encoding;
     return mysql_set_charset($encoding, $this->connection);
 }
示例#16
0
 function clientEncoding()
 {
     /* 返回字符集的名称 */
     return mysql_client_encoding($this->LinkId);
 }
示例#17
0
 /**
  *	Ouverture d'une connexion vers le serveur et eventuellement une database.
  *	@param      type		Type de base de donnees (mysql ou pgsql)
  *	@param	    host		Addresse de la base de donnees
  *	@param	    user		Nom de l'utilisateur autorise
  *	@param	    pass		Mot de passe
  *	@param	    name		Nom de la database
  *	@param	    port		Port of database server
  *	@return	    int			1 en cas de succes, 0 sinon
  */
 function DoliDb($type = 'mysql', $host, $user, $pass, $name = '', $port = 0)
 {
     global $conf, $langs;
     if (!empty($conf->db->character_set)) {
         $this->forcecharset = $conf->db->character_set;
     }
     if (!empty($conf->db->dolibarr_main_db_collation)) {
         $this->forcecollate = $conf->db->dolibarr_main_db_collation;
     }
     $this->database_user = $user;
     $this->transaction_opened = 0;
     //print "Name DB: $host,$user,$pass,$name<br>";
     if (!function_exists("mysql_connect")) {
         $this->connected = 0;
         $this->ok = 0;
         $this->error = "Mysql PHP functions for using MySql driver are not available in this version of PHP. Try to use another driver.";
         dol_syslog("DoliDB::DoliDB : Mysql PHP functions for using Mysql driver are not available in this version of PHP. Try to use another driver.", LOG_ERR);
         return $this->ok;
     }
     if (!$host) {
         $this->connected = 0;
         $this->ok = 0;
         $this->error = $langs->trans("ErrorWrongHostParameter");
         dol_syslog("DoliDB::DoliDB : Erreur Connect, wrong host parameters", LOG_ERR);
         return $this->ok;
     }
     // Essai connexion serveur
     $this->db = $this->connect($host, $user, $pass, $name, $port);
     if ($this->db) {
         $this->connected = 1;
         $this->ok = 1;
     } else {
         // host, login ou password incorrect
         $this->connected = 0;
         $this->ok = 0;
         $this->error = mysql_error();
         dol_syslog("DoliDB::DoliDB : Erreur Connect mysql_error=" . $this->error, LOG_ERR);
     }
     // Si connexion serveur ok et si connexion base demandee, on essaie connexion base
     if ($this->connected && $name) {
         if ($this->select_db($name)) {
             $this->database_selected = 1;
             $this->database_name = $name;
             $this->ok = 1;
             // If client connected with different charset than Dolibarr HTML output
             $clientmustbe = '';
             if (preg_match('/UTF-8/i', $conf->file->character_set_client)) {
                 $clientmustbe = 'utf8';
             }
             if (preg_match('/ISO-8859-1/i', $conf->file->character_set_client)) {
                 $clientmustbe = 'latin1';
             }
             if (mysql_client_encoding($this->db) != $clientmustbe) {
                 $this->query("SET NAMES '" . $clientmustbe . "'", $this->db);
                 //$this->query("SET CHARACTER SET ". $this->forcecharset);
             }
         } else {
             $this->database_selected = 0;
             $this->database_name = '';
             $this->ok = 0;
             $this->error = $this->error();
             dol_syslog("DoliDB::DoliDB : Erreur Select_db " . $this->error, LOG_ERR);
         }
     } else {
         // Pas de selection de base demandee, ok ou ko
         $this->database_selected = 0;
         if ($this->connected) {
             // If client connected with different charset than Dolibarr HTML output
             $clientmustbe = '';
             if (preg_match('/UTF-8/i', $conf->file->character_set_client)) {
                 $clientmustbe = 'utf8';
             }
             if (preg_match('/ISO-8859-1/i', $conf->file->character_set_client)) {
                 $clientmustbe = 'latin1';
             }
             if (mysql_client_encoding($this->db) != $clientmustbe) {
                 $this->query("SET NAMES '" . $clientmustbe . "'", $this->db);
                 //$this->query("SET CHARACTER SET ". $this->forcecharset);
             }
         }
     }
     return $this->ok;
 }
} else {
    print "SUCCESS: connect\n";
}
if (!mysql_select_db($db, $con)) {
    printf("FAILURE: [%d] %s\n", mysql_errno($con), mysql_error($con));
}
$encoding_default = mysql_client_encoding();
$encoding_con = mysql_client_encoding($con);
if ($encoding_con != $encoding_default) {
    printf("FAILURE: different client encodings reported, [%d] %s\n", mysql_errno($con), mysql_error($con));
} else {
    if (!is_string($encoding_con)) {
        printf("FAILURE: no string returned, [%d] %s\n", mysql_errno($con), mysql_error($con));
    }
}
$encoding_con = mysql_client_encoding($illegal_link_identifier);
if (!is_null($encoding_con)) {
    printf("FAILURE: NULL value expected, got %s value\n", gettype($encoding_con));
}
mysql_close($con);
?>
--EXPECT-EXT/MYSQL-OUTPUT--
SUCCESS: connect

--EXPECT-EXT/MYSQL-PHP-ERRORS--
--EXPECT-EXT/MYSQLI-OUTPUT--
SUCCESS: connect

--EXPECT-EXT/MYSQLI-PHP-ERRORS--
43, E_NOTICE, Undefined variable: illegal_link_identifier
43, E_WARNING, mysqli_character_set_name() expects parameter 1 to be mysqli, null given
示例#19
0
 }
 if (substr($line, 0, 2) == "--" or empty($line)) {
     continue;
 }
 $line = str_replace("/*!40000", "", $line);
 $line = str_replace("/*!40101", "", $line);
 $line = str_replace("/*!40103", "", $line);
 $line = str_replace("/*!40014", "", $line);
 $line = str_replace("/*!40111", "", $line);
 $line = str_replace("*/;", ";", trim($line));
 if (substr($line, 0, 9) == "SET NAMES") {
     $chrset = trim(str_replace("'", "", substr($line, 10, -1)));
     if (function_exists("mysql_set_charset")) {
         mysql_set_charset($chrset);
     }
     if (defined('DB_CHARSET') and $chrset != DB_CHARSET or $chrset != mysql_client_encoding()) {
         echo __('ERROR:', 'backwpup') . ' ' . sprintf(__('Pleace set <i>define(\'DB_CHARSET\', \'%1$s\');</i> in wp-config.php', 'backwpup'), $chrset) . "<br />\n";
         break;
     }
 }
 $command = "";
 if (";" == substr($line, -1)) {
     $command = $rest . $line;
     $rest = "";
 } else {
     $rest .= $line;
 }
 if (!empty($command)) {
     $result = mysql_query($command);
     if ($sqlerr = mysql_error($wpdb->dbh)) {
         echo __('ERROR:', 'backwpup') . ' ' . sprintf(__('BackWPup database error %1$s for query %2$s', 'backwpup'), $sqlerr, $command) . "<br />\n";
示例#20
0
 public function getDbInfo()
 {
     $charsets = $this->getCharsetInfo();
     $charset_str = array();
     foreach ($charsets as $name => $value) {
         $charset_str[] = "{$name} = {$value}";
     }
     return array("MySQL Version" => @mysql_get_client_info(), "MySQL Host Info" => @mysql_get_host_info($this->database), "MySQL Server Info" => @mysql_get_server_info($this->database), "MySQL Client Encoding" => @mysql_client_encoding($this->database), "MySQL Character Set Settings" => join(", ", $charset_str));
 }
示例#21
0
    }
    return $vModules;
}
/** get a module setting */
function getModuleSetting($pModuleName, $pSetting)
{
    $vModules = parsePHPModules();
    return $vModules[$pModuleName][$pSetting];
}
echo '<P CLASS="page_title_text"><img src="' . $rootpath . '/css/' . $theme . '/images/maintenance.png" TITLE="' . _('System Check') . '" ALT="">' . ' ' . _('System Check') . '</P><CENTER>';
echo '<DIV class="system_check">';
echo '<h3>PHP Settings</h3>';
echo '<p>PHP version: ' . phpversion();
echo '<p>GD Module: ' . getModuleSetting('gd', 'GD Version') . '</p>';
echo '<p>MYSQL Module: ' . getModuleSetting('mysql', 'Client API version') . '</p>';
echo '<p>MySQL character set: ' . mysql_client_encoding();
echo '<p>Zlib: ' . getModuleSetting('zlib', 'ZLib Support') . '</p>';
echo '<p>Simple XML: ' . getModuleSetting('SimpleXML', 'Revision') . '</p>';
echo '<h3>Linux System Settings</h3>';
ob_start();
echo "<p><b>Memory Free</b></br>";
passthru('free');
echo "<p><b>CPU type</b></br>";
passthru('cat /proc/cpuinfo | grep "model name" ');
echo "<p><b>Disk Space Free</b><br>";
system('df');
echo "<p><b>webERP Disk Space Usage</b><br>";
system('du -sh');
echo "<p>";
$fr = ob_get_contents();
ob_end_clean();
示例#22
0
function executemysql($getinfo, $getdumps, $getschema)
{
    //BEGIN GET DB INFO
    global $getDumpsFrom;
    global $curdatetime;
    global $sugar_config;
    global $progress_bar_percent;
    global $sod_guid;
    global $db;
    if ($db->dbType != "mysql") {
        if ($getinfo) {
            sodUpdateProgressBar(MYSQL_INFO_WEIGHT);
        }
        if ($getschema) {
            sodUpdateProgressBar(MYSQL_SCHEMA_WEIGHT);
        }
        if ($getdumps) {
            sodUpdateProgressBar(MYSQL_DUMPS_WEIGHT);
        }
        return;
    }
    $mysqlInfoDir = create_cache_directory("diagnostic/" . $sod_guid . "/diagnostic" . $curdatetime . "/MySQL/");
    //create directory for table definitions
    if ($getschema) {
        $tablesSchemaDir = create_cache_directory("diagnostic/" . $sod_guid . "/diagnostic" . $curdatetime . "/MySQL/TableSchema/");
    }
    //BEGIN GET MYSQL INFO
    //make sure they checked the box to get basic info
    if ($getinfo) {
        ob_start();
        echo "MySQL Version: " . (function_exists('mysqli_get_client_info') ? @mysqli_get_client_info() : @mysql_get_client_info()) . "<BR>";
        echo "MySQL Host Info: " . (function_exists('mysqli_get_host_info') ? @mysqli_get_host_info($db->getDatabase()) : @mysql_get_host_info()) . "<BR>";
        echo "MySQL Server Info: " . (function_exists('mysqli_get_client_info') ? @mysqli_get_client_info() : @mysql_get_client_info()) . "<BR>";
        echo "MySQL Client Encoding: " . (function_exists('mysqli_character_set_name') ? @mysqli_character_set_name($db->getDatabase()) : @mysql_client_encoding()) . "<BR>";
        /* Uncomment to get current processes as well
           echo "<BR>MySQL Processes<BR>";
           $res = $db->query('SHOW PROCESSLIST');
           echo "<table border=\"1\"><tr><th>Id</th><th>Host</th><th>db</th><th>Command</th><th>Time</th></tr>";
           if($db->getRowCount($res) > 0)
           {
             while($row = $db->fetchByAssoc($res))
             {
               printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>",
                      $row['Id'], $row['Host'], $row['db'], $row['Command'], $row['Time']
                      );
             }
             echo "</table><br>";
           }
           else
           {
             echo "</table>";
             echo "No processes running<br>";
           }
           */
        echo "<BR>MySQL Character Set Settings<BR>";
        $res = $db->query("show variables like 'character\\_set\\_%'");
        echo "<table border=\"1\"><tr><th>Variable Name</th><th>Value</th></tr>";
        while ($row = $db->fetchByAssoc($res)) {
            printf("<tr><td>%s</td><td>%s</td></tr>", $row['Variable_name'], $row['Value']);
        }
        echo "</table>";
        $content = ob_get_contents();
        ob_clean();
        $handle = sugar_fopen($mysqlInfoDir . "MySQL-General-info.html", "w");
        if (fwrite($handle, $content) === FALSE) {
            echo "Cannot write to file " . $mysqlInfoDir . "_MySQL-General-info.html<br>";
        }
        fclose($handle);
        //BEGIN UPDATING PROGRESS BAR
        sodUpdateProgressBar(MYSQL_INFO_WEIGHT);
        //END UPDATING PROGRESS BAR
    }
    //END GET MYSQL INFO
    if ($getschema) {
        //BEGIN GET ALL TABLES SCHEMAS
        $all_tables = $db->getTablesArray();
        global $theme_path;
        ob_start();
        echo "<style>";
        echo file_get_contents($theme_path . "style.css");
        echo "</style>";
        foreach ($all_tables as $tablename) {
            //setting up table header for each file
            echo "<table border=\"0\" cellpadding=\"0\" class=\"tabDetailView\">";
            echo "<tr>MySQL " . $tablename . " Definitions:</tr>" . "<tr><td class=\"tabDetailViewDL\"><b>Field</b></td>" . "<td class=\"tabDetailViewDL\">Type</td>" . "<td class=\"tabDetailViewDL\">Null</td>" . "<td class=\"tabDetailViewDL\">Key</td>" . "<td class=\"tabDetailViewDL\">Default</td>" . "<td class=\"tabDetailViewDL\">Extra</td></tr>";
            $describe = $db->query("describe " . $tablename);
            while ($inner_row = $db->fetchByAssoc($describe)) {
                $inner_row = array_values($inner_row);
                echo "<tr><td class=\"tabDetailViewDF\"><b>" . $inner_row[0] . "</b></td>";
                echo "<td class=\"tabDetailViewDF\">" . $inner_row[1] . "</td>";
                echo "<td class=\"tabDetailViewDF\">" . $inner_row[2] . "</td>";
                echo "<td class=\"tabDetailViewDF\">" . $inner_row[3] . "</td>";
                echo "<td class=\"tabDetailViewDF\">" . $inner_row[4] . "</td>";
                echo "<td class=\"tabDetailViewDF\">" . $inner_row[5] . "</td></tr>";
            }
            echo "</table>";
            echo "<BR><BR>";
        }
        $content = ob_get_contents();
        ob_clean();
        $handle = sugar_fopen($tablesSchemaDir . "MySQLTablesSchema.html", "w");
        if (fwrite($handle, $content) === FALSE) {
            echo "Cannot write to file " . $tablesSchemaDir . "MySQLTablesSchema.html<br>";
        }
        fclose($handle);
        //END GET ALL TABLES SCHEMAS
        //BEGIN UPDATING PROGRESS BAR
        sodUpdateProgressBar(MYSQL_SCHEMA_WEIGHT);
        //END UPDATING PROGRESS BAR
    }
    if ($getdumps) {
        //BEGIN GET TABLEDUMPS
        $tableDumpsDir = create_cache_directory("diagnostic/" . $sod_guid . "/diagnostic" . $curdatetime . "/MySQL/TableDumps/");
        foreach ($getDumpsFrom as $table) {
            ob_start();
            //calling function defined above to get the string for dump
            echo getFullTableDump($table);
            $content = ob_get_contents();
            ob_clean();
            $handle = sugar_fopen($tableDumpsDir . $table . ".html", "w");
            if (fwrite($handle, $content) === FALSE) {
                echo "Cannot write to file " . $tableDumpsDir . $table . "html<br>";
            }
            fclose($handle);
        }
        //END GET TABLEDUMPS
        //BEGIN UPDATING PROGRESS BAR
        sodUpdateProgressBar(MYSQL_DUMPS_WEIGHT);
        //END UPDATING PROGRESS BAR
    }
    //END GET DB INFO
}
示例#23
0
 /**
  * Test mysql_set_charset
  *
  * @return boolean
  */
 public function MySQL_Set_Charset_Test()
 {
     // Set charset
     $charset = 'latin1';
     mysql_set_charset($charset);
     // Get charset
     $enc1 = mysql_client_encoding();
     return $enc1 === "latin1";
 }
示例#24
0
 /**
  * Test mysql_set_charset
  *
  * @return boolean
  */
 public function MySQL_Set_Charset_Test()
 {
     // Set charset
     $charset = 'latin1';
     mysql_set_charset($charset);
     $this->_object->mysql_set_charset($charset);
     // Get charset
     $enc1 = mysql_client_encoding();
     $enc2 = $this->_object->mysql_client_encoding();
     return $enc1 === $enc2;
 }
示例#25
0
function doDiagnostics()
{
    global $files, $txpcfg, $step;
    extract(get_prefs());
    $urlparts = parse_url(hu);
    $mydomain = $urlparts['host'];
    $server_software = @$_SERVER['SERVER_SOFTWARE'] || @$_SERVER['HTTP_HOST'] ? @$_SERVER['SERVER_SOFTWARE'] ? @$_SERVER['SERVER_SOFTWARE'] : $_SERVER['HTTP_HOST'] : '';
    $is_apache = ($server_software and stristr($server_software, 'Apache')) or is_callable('apache_get_version');
    $real_doc_root = isset($_SERVER['DOCUMENT_ROOT']) ? realpath($_SERVER['DOCUMENT_ROOT']) : '';
    // ini_get() returns string values passed via php_value as a string, not boolean
    $is_register_globals = (strcasecmp(ini_get('register_globals'), 'on') === 0 or ini_get('register_globals') === '1');
    $fail = array('path_to_site_missing' => !isset($path_to_site) ? gTxt('path_to_site_missing') : '', 'dns_lookup_fails' => @gethostbyname($mydomain) == $mydomain ? gTxt('dns_lookup_fails') . cs . $mydomain : '', 'path_to_site_inacc' => !@is_dir($path_to_site) ? gTxt('path_to_site_inacc') . cs . $path_to_site : '', 'site_trailing_slash' => rtrim($siteurl, '/') != $siteurl ? gTxt('site_trailing_slash') . cs . $path_to_site : '', 'index_inaccessible' => (!@is_file($path_to_site . "/index.php") or !@is_readable($path_to_site . "/index.php")) ? "{$path_to_site}/index.php " . gTxt('is_inaccessible') : '', 'dir_not_writable' => trim((!@is_writable($path_to_site . '/' . $img_dir) ? str_replace('{dirtype}', gTxt('img_dir'), gTxt('dir_not_writable')) . ": {$path_to_site}/{$img_dir}\r\n" : '') . (!@is_writable($file_base_path) ? str_replace('{dirtype}', gTxt('file_base_path'), gTxt('dir_not_writable')) . ": {$file_base_path}\r\n" : '') . (!@is_writable($tempdir) ? str_replace('{dirtype}', gTxt('tempdir'), gTxt('dir_not_writable')) . ": {$tempdir}\r\n" : '')), 'cleanurl_only_apache' => ($permlink_mode != 'messy' and !$is_apache) ? gTxt('cleanurl_only_apache') : '', 'htaccess_missing' => ($permlink_mode != 'messy' and !@is_readable($path_to_site . '/.htaccess')) ? gTxt('htaccess_missing') : '', 'mod_rewrite_missing' => ($permlink_mode != 'messy' and is_callable('apache_get_modules') and !apache_module('mod_rewrite')) ? gTxt('mod_rewrite_missing') : '', 'file_uploads_disabled' => !ini_get('file_uploads') ? gTxt('file_uploads_disabled') : '', 'setup_still_exists' => @is_dir($txpcfg['txpath'] . DS . 'setup') ? $txpcfg['txpath'] . DS . "setup" . DS . ' ' . gTxt('still_exists') : '', 'no_temp_dir' => empty($tempdir) ? gTxt('no_temp_dir') : '', 'warn_mail_unavailable' => !is_callable('mail') ? gTxt('warn_mail_unavailable') : '', 'warn_register_globals_or_update' => $is_register_globals && (version_compare(phpversion(), '4.4.0', '<=') or version_compare(phpversion(), '5.0.0', '>=') and version_compare(phpversion(), '5.0.5', '<=')) ? gTxt('warn_register_globals_or_update') : '');
    if ($permlink_mode != 'messy') {
        $rs = safe_column("name", "txp_section", "1");
        foreach ($rs as $name) {
            if (@file_exists($path_to_site . '/' . $name)) {
                $fail['old_placeholder_exists'] = gTxt('old_placeholder') . ": {$path_to_site}/{$name}";
            }
        }
    }
    $missing = array();
    foreach ($files as $f) {
        if (!is_readable($txpcfg['txpath'] . $f)) {
            $missing[] = $txpcfg['txpath'] . $f;
        }
    }
    if ($missing) {
        $fail['missing_files'] = gTxt('missing_files') . cs . join(', ', $missing);
    }
    foreach ($fail as $k => $v) {
        if (empty($v)) {
            unset($fail[$k]);
        }
    }
    # Find the highest revision number
    $file_revs = array();
    $rev = 0;
    foreach ($files as $f) {
        $lines = @file($txpcfg['txpath'] . $f);
        if ($lines) {
            foreach ($lines as $line) {
                if (preg_match('/^\\$LastChangedRevision: (\\w+) \\$/', $line, $match)) {
                    $file_revs[$f] = $match[1];
                    if ($match[1] > $rev) {
                        $rev = $match[1];
                    }
                }
            }
        }
    }
    echo pagetop(gTxt('tab_diagnostics'), ''), startTable('list'), tr(td(hed(gTxt('preflight_check'), 1)));
    if ($fail) {
        foreach ($fail as $help => $message) {
            echo tr(tda(nl2br($message) . popHelp($help), ' style="color:red;"'));
        }
    } else {
        echo tr(td(gTxt('all_checks_passed')));
    }
    echo tr(td(hed(gTxt('diagnostic_info'), 1)));
    $fmt_date = '%Y-%m-%d %H:%M:%S';
    $out = array('<textarea style="width:500px;height:300px;" readonly="readonly">', gTxt('txp_version') . cs . txp_version . ' (' . ($rev ? 'r' . $rev : 'unknown revision') . ')' . n, gTxt('last_update') . cs . gmstrftime($fmt_date, $dbupdatetime) . '/' . gmstrftime($fmt_date, @filemtime(txpath . '/update/_update.php')) . n, gTxt('document_root') . cs . @$_SERVER['DOCUMENT_ROOT'] . ($real_doc_root != @$_SERVER['DOCUMENT_ROOT'] ? ' (' . $real_doc_root . ')' : '') . n, '$path_to_site' . cs . $path_to_site . n, gTxt('txp_path') . cs . $txpcfg['txpath'] . n, gTxt('permlink_mode') . cs . $permlink_mode . n, ini_get('open_basedir') ? 'open_basedir: ' . ini_get('open_basedir') . n : '', ini_get('upload_tmp_dir') ? 'upload_tmp_dir: ' . ini_get('upload_tmp_dir') . n : '', gTxt('tempdir') . cs . $tempdir . n, gTxt('web_domain') . cs . $siteurl . n, getenv('TZ') ? 'TZ: ' . getenv('TZ') . n : '', gTxt('php_version') . cs . phpversion() . n, $is_register_globals ? gTxt('register_globals') . cs . $is_register_globals . n : '', gTxt('server_time') . cs . strftime('%Y-%m-%d %H:%M:%S') . n, 'MySQL' . cs . mysql_get_server_info() . n, gTxt('locale') . cs . $locale . n, isset($_SERVER['SERVER_SOFTWARE']) ? gTxt('server') . cs . $_SERVER['SERVER_SOFTWARE'] . n : '', is_callable('apache_get_version') ? gTxt('apache_version') . cs . apache_get_version() . n : '', $fail ? n . gTxt('preflight_check') . cs . n . ln . join("\n", $fail) . n . ln : '', is_readable($path_to_site . '/.htaccess') ? n . gTxt('htaccess_contents') . cs . n . ln . join('', file($path_to_site . '/.htaccess')) . n . ln : '');
    if ($step == 'high') {
        $mysql_client_encoding = is_callable('mysql_client_encoding') ? mysql_client_encoding() : '-';
        $out[] = n . 'Charset (default/config)' . cs . $mysql_client_encoding . '/' . @$txpcfg['dbcharset'] . n;
        $result = safe_query("SHOW variables like 'character_se%'");
        while ($row = mysql_fetch_row($result)) {
            $out[] = $row[0] . cs . $row[1] . n;
            if ($row[0] == 'character_set_connection') {
                $conn_char = $row[1];
            }
        }
        $table_names = array(PFX . 'textpattern');
        $result = safe_query("SHOW TABLES LIKE '" . PFX . "txp\\_%'");
        while ($row = mysql_fetch_row($result)) {
            $table_names[] = $row[0];
        }
        $table_msg = array();
        foreach ($table_names as $table) {
            $ctr = safe_query("SHOW CREATE TABLE " . $table . "");
            if (!$ctr) {
                unset($table_names[$table]);
                continue;
            }
            $ctcharset = preg_replace('#^CREATE TABLE.*SET=([^ ]+)[^)]*$#is', '\\1', mysql_result($ctr, 0, 'Create Table'));
            if (isset($conn_char) && !stristr($ctcharset, 'CREATE') && $conn_char != $ctcharset) {
                $table_msg[] = "{$table} is {$ctcharset}";
            }
            $ctr = safe_query("CHECK TABLE " . $table);
            if (in_array(mysql_result($ctr, 0, 'Msg_type'), array('error', 'warning'))) {
                $table_msg[] = $table . cs . mysql_result($ctr, 0, 'Msg_Text');
            }
        }
        if ($table_msg == array()) {
            $table_msg = count($table_names) < 18 ? array('-') : array('OK');
        }
        $out[] = count($table_names) . ' Tables' . cs . implode(', ', $table_msg) . n;
        $extns = get_loaded_extensions();
        $extv = array();
        foreach ($extns as $e) {
            $extv[] = $e . (phpversion($e) ? '/' . phpversion($e) : '');
        }
        $out[] = n . gTxt('php_extensions') . cs . join(', ', $extv) . n;
        if (is_callable('apache_get_modules')) {
            $out[] = n . gTxt('apache_modules') . cs . join(', ', apache_get_modules()) . n . n;
        }
        foreach ($files as $f) {
            $rev = '';
            $checksum = '';
            if (is_callable('md5_file')) {
                $checksum = md5_file($txpcfg['txpath'] . $f);
            }
            if (isset($file_revs[$f])) {
                $rev = $file_revs[$f];
            }
            $out[] = "{$f}" . cs . ($rev ? "r" . $rev : gTxt('unknown')) . ' (' . ($checksum ? $checksum : gTxt('unknown')) . ')' . n;
        }
    }
    $out[] = '</textarea>' . br;
    $dets = array('low' => gTxt('low'), 'high' => gTxt('high'));
    $out[] = form(eInput('diag') . n . gTxt('detail') . cs . selectInput('step', $dets, $step, 0, 1));
    echo tr(td(join('', $out))), endTable();
}
echo 'Отчество: ' . sha1($third_name) . '<br />';
echo '<h4>Работа с базой данных: </h4>';
$db_connect = mysql_connect('localhost', 'developer', 'developerpass');
if ($db_connect) {
    //Открыть соединение с MysSQL
    echo 'Соединение с MySQL установлено.<br />';
    echo 'ID соединения: ' . $db_connect . '<br />';
    mysql_select_db('php_development', $db_connect);
    $db_query = "INSERT INTO form_data (`first_name`, `second_name`, `third_name`) VALUES ('{$first_name}', '{$second_name}', '{$third_name}')";
    if (mysql_query($db_query, $db_connect)) {
        //Сделать запись для данного соединения
        echo '1 запись добавлена.<br />';
        //Сообщить об успешной записи
    } else {
        echo 'Ошибка добавления записи: ' . mysql_error() . '.<br />';
        //Вывести ошибку MySQL
    }
    echo 'Кодировка соединения: ' . mysql_client_encoding() . '.<br />';
} else {
    echo 'Соединение с MySQL не установлено. <br />';
}
//INSERT INTO `php_development`.`form_data` (`id`, `first_name`, `second_name`, `third_name`) VALUES ('2', 'Ryapolov', 'Artem', 'Vladimirovich');
if (mysql_close()) {
    //Закрыть соединение с MySQL
    echo 'Соединение с MySQL закрыто.<br />';
} else {
    echo 'Соединение с MySQL не закрыто.<br />';
}
?>
    </body>
</html>
示例#27
0
    /**
     * Strips any invalid characters based on value/charset pairs.
     *
     * @since 4.2.0
     * @access protected
     *
     * @param array $data Array of value arrays. Each value array has the keys
     *                    'value' and 'charset'. An optional 'ascii' key can be
     *                    set to false to avoid redundant ASCII checks.
     * @return array|WP_Error The $data parameter, with invalid characters removed from
     *                        each value. This works as a passthrough: any additional keys
     *                        such as 'field' are retained in each value array. If we cannot
     *                        remove invalid characters, a WP_Error object is returned.
     */
    protected function strip_invalid_text($data)
    {
        $db_check_string = false;
        foreach ($data as &$value) {
            $charset = $value['charset'];
            if (is_array($value['length'])) {
                $length = $value['length']['length'];
                $truncate_by_byte_length = 'byte' === $value['length']['type'];
            } else {
                $length = false;
                // Since we have no length, we'll never truncate.
                // Initialize the variable to false. true would take us
                // through an unnecessary (for this case) codepath below.
                $truncate_by_byte_length = false;
            }
            // There's no charset to work with.
            if (false === $charset) {
                continue;
            }
            // Column isn't a string.
            if (!is_string($value['value'])) {
                continue;
            }
            $needs_validation = true;
            if ('latin1' === $charset || !isset($value['ascii']) && $this->check_ascii($value['value'])) {
                $truncate_by_byte_length = true;
                $needs_validation = false;
            }
            if ($truncate_by_byte_length) {
                mbstring_binary_safe_encoding();
                if (false !== $length && strlen($value['value']) > $length) {
                    $value['value'] = substr($value['value'], 0, $length);
                }
                reset_mbstring_encoding();
                if (!$needs_validation) {
                    continue;
                }
            }
            // utf8 can be handled by regex, which is a bunch faster than a DB lookup.
            if (('utf8' === $charset || 'utf8mb3' === $charset || 'utf8mb4' === $charset) && function_exists('mb_strlen')) {
                $regex = '/
					(
						(?: [\\x00-\\x7F]                  # single-byte sequences   0xxxxxxx
						|   [\\xC2-\\xDF][\\x80-\\xBF]       # double-byte sequences   110xxxxx 10xxxxxx
						|   \\xE0[\\xA0-\\xBF][\\x80-\\xBF]   # triple-byte sequences   1110xxxx 10xxxxxx * 2
						|   [\\xE1-\\xEC][\\x80-\\xBF]{2}
						|   \\xED[\\x80-\\x9F][\\x80-\\xBF]
						|   [\\xEE-\\xEF][\\x80-\\xBF]{2}';
                if ('utf8mb4' === $charset) {
                    $regex .= '
						|    \\xF0[\\x90-\\xBF][\\x80-\\xBF]{2} # four-byte sequences   11110xxx 10xxxxxx * 3
						|    [\\xF1-\\xF3][\\x80-\\xBF]{3}
						|    \\xF4[\\x80-\\x8F][\\x80-\\xBF]{2}
					';
                }
                $regex .= '){1,40}                          # ...one or more times
					)
					| .                                  # anything else
					/x';
                $value['value'] = preg_replace($regex, '$1', $value['value']);
                if (false !== $length && mb_strlen($value['value'], 'UTF-8') > $length) {
                    $value['value'] = mb_substr($value['value'], 0, $length, 'UTF-8');
                }
                continue;
            }
            // We couldn't use any local conversions, send it to the DB.
            $value['db'] = $db_check_string = true;
        }
        unset($value);
        // Remove by reference.
        if ($db_check_string) {
            $queries = array();
            foreach ($data as $col => $value) {
                if (!empty($value['db'])) {
                    // We're going to need to truncate by characters or bytes, depending on the length value we have.
                    if ('byte' === $value['length']['type']) {
                        // Using binary causes LEFT() to truncate by bytes.
                        $charset = 'binary';
                    } else {
                        $charset = $value['charset'];
                    }
                    if ($this->charset) {
                        $connection_charset = $this->charset;
                    } else {
                        if ($this->use_mysqli) {
                            $connection_charset = mysqli_character_set_name($this->dbh);
                        } else {
                            $connection_charset = mysql_client_encoding();
                        }
                    }
                    if (is_array($value['length'])) {
                        $queries[$col] = $this->prepare("CONVERT( LEFT( CONVERT( %s USING {$charset} ), %.0f ) USING {$connection_charset} )", $value['value'], $value['length']['length']);
                    } else {
                        if ('binary' !== $charset) {
                            // If we don't have a length, there's no need to convert binary - it will always return the same result.
                            $queries[$col] = $this->prepare("CONVERT( CONVERT( %s USING {$charset} ) USING {$connection_charset} )", $value['value']);
                        }
                    }
                    unset($data[$col]['db']);
                }
            }
            $sql = array();
            foreach ($queries as $column => $query) {
                if (!$query) {
                    continue;
                }
                $sql[] = $query . " AS x_{$column}";
            }
            $this->check_current_query = false;
            $row = $this->get_row("SELECT " . implode(', ', $sql), ARRAY_A);
            if (!$row) {
                return new WP_Error('wpdb_strip_invalid_text_failure');
            }
            foreach (array_keys($data) as $column) {
                if (isset($row["x_{$column}"])) {
                    $data[$column]['value'] = $row["x_{$column}"];
                }
            }
        }
        return $data;
    }
示例#28
0
</b></td></tr><?php 
# Check MySQL version
if ($use_mysqli) {
    $mysqlversion = mysqli_get_server_info($db);
} else {
    $mysqlversion = mysql_get_server_info();
}
if ($mysqlversion < '5') {
    $result = $lang["status-fail"] . ": " . str_replace("?", "5", $lang["shouldbeversion"]);
} else {
    $result = $lang["status-ok"];
}
if ($use_mysqli) {
    $encoding = mysqli_character_set_name($db);
} else {
    $encoding = mysql_client_encoding();
}
?>
<tr><td><?php 
echo str_replace("?", "MySQL", $lang["softwareversion"]);
?>
</td><td><?php 
echo $mysqlversion . "&ensp;&ensp;" . str_replace("%encoding", $encoding, $lang["client-encoding"]);
?>
</td><td><b><?php 
echo $result;
?>
</b></td></tr><?php 
# Check GD installed
if (function_exists("gd_info")) {
    $gdinfo = gd_info();
示例#29
0
 /**
  * Gets the database encoding
  *
  * @return string The database encoding
  */
 function getEncoding()
 {
     return mysql_client_encoding($this->connection);
 }
示例#30
0
function sql_doconnect()
{
    global $dconf;
    if (!strlen(trim($dconf['dbhost']))) {
        print "<h4>MySQL server not specified</h4>\n";
        return false;
    }
    if (!strlen(trim($dconf['dbuser']))) {
        print "<h4>MySQL server username not specified</h4>\n";
        return false;
    }
    if ($dconf['verbose']) {
        print "<pre>\n";
    }
    //
    // first try to connect to master server
    //
    $mysid = 1;
    $mysserv = $dconf['dbhost'];
    $mysuser = $dconf['dbuser'];
    $myspass = $dconf['dbpass'];
    $mysdb = $dconf['dbname'];
    $myc = false;
    while (true) {
        if ($dconf['verbose']) {
            print "Connecting to mysql://" . $mysuser . "@" . $mysserv . "/" . $mysdb . "...\n";
        }
        if (!strlen(trim($myspass))) {
            $myc = mysql_connect($mysserv, $mysuser);
        } else {
            $myc = mysql_connect($mysserv, $mysuser, $myspass);
        }
        if (!$myc) {
            print "<h4>Unable to connect to " . $mysserv . "</h4>\n";
        } else {
            if (!mysql_select_db($mysdb, $myc)) {
                print "<h4>Could not select database " . $mysdb . "</h4>\n";
            }
        }
        flush();
        if ($myc || $mysid > 1) {
            break;
        } else {
            //
            // try next secondary server
            //
            $mysid = 2;
            $mysserv = $dconf['dbsechost'];
            $mysuser = $dconf['dbsecuser'];
            $myspass = $dconf['dbsecpass'];
            $mysdb = $dconf['dbsecname'];
        }
    }
    if ($dconf['verbose']) {
        print "Connected to MySQL server " . mysql_get_server_info() . " at " . mysql_get_host_info() . "\n";
        print "Selected database: " . $mysdb . "\n";
        print "Client encoding: " . mysql_client_encoding() . "\n";
    }
    if ($dconf['verbose']) {
        print "</pre>\n";
    }
    sql_setcharset($myc, 'utf8');
    return $myc;
}