/** * 创建数据库连接 * @param string $k 配置文件key * @return resource */ function db($k = 'default') { $conf = conf('db', $k); if (!$conf) { trigger_error('Can\'t find $GLOBALS[\'db\'][\'' . $k . '\'] - in database.conf.php'); } $db_key = md5("{$conf['hostname']}-{$conf['username']}-{$conf['password']}-{$conf['database']}"); if (!isset($GLOBALS[$db_key])) { $server = $conf['hostname'] . ':' . $conf['port']; $link = mysql_connect($server, $conf['username'], $conf['password'], TRUE); if (!$link) { trigger_error('Connect database be fail, Pealse inspect yours database setting!'); } if (!mysql_select_db($conf['database'], $link)) { trigger_error("Can't select database - {$conf['database']}, Pealse inspect yours database setting"); } if (function_exists('mysql_set_charset')) { $is_set_charset = mysql_set_charset($conf['char_set']); } else { if (function_exists('mysqli_character_set_name')) { $is_set_charset = mysqli_character_set_name($conf['char_set']); } else { $is_set_charset = mysql_query("SET names '{$conf['char_set']}'"); } } if ($is_set_charset != TRUE) { exit('charset error!'); } //mysql_query( "SET names = '{$conf['char_set']}'" ); mysql_query("SET CHARACTER SET '{$conf['char_set']}'"); $GLOBALS[$db_key] = $link; } return $GLOBALS[$db_key]; }
private final function CreateLink() { $this->link = mysqli_connect('localhost', 'panel', '1q2w3e4r', $this->dbname) or $this->ErrorMsg(mysqli_connect_error()); if (mysqli_character_set_name($this->link) != 'utf8') { if (!mysqli_set_charset($this->link, 'utf8')) { $this->ErrorMsg(mysqli_error($this->link)); } } }
function obtenerTodasLasFallas() { $fallas = array(); $sql = "SELECT id, nombre_falla FROM operaciones_fallas ORDER BY nombre_falla ASC"; $link = Conectarse(); // obtenemos todos los países $result = mysqli_query($link, $sql); // creamos objetos de la clase país y los agregamos al arreglo while ($row = $result->fetch_assoc()) { $row['nombre_falla'] = mb_convert_encoding($row['nombre_falla'], 'UTF-8', mysqli_character_set_name($link)); $falla = new falla($row['id'], $row['nombre_falla']); array_push($fallas, $falla); } // devolvemos el arreglo return $fallas; }
function obtenerTodosLosEquipos() { $equipos = array(); $sql = "SELECT id, nombre FROM operaciones_equipos ORDER BY nombre ASC"; $link = Conectarse(); // obtenemos todos los países $result = mysqli_query($link, $sql); // creamos objetos de la clase país y los agregamos al arreglo while ($row = $result->fetch_assoc()) { $row['nombre'] = mb_convert_encoding($row['nombre'], 'UTF-8', mysqli_character_set_name($link)); $equipo = new equipo($row['id'], $row['nombre']); array_push($equipos, $equipo); } // devolvemos el arreglo return $equipos; }
function obtenerCursos() { $estatus = "ABIERTO"; $cursos = array(); $sql = "SELECT id, nombre \r\n FROM cursos WHERE estatus ='ABIERTO'"; $db = obtenerConexion(); // obtenemos todos las sedes $result = ejecutarQuery($db, $sql); // creamos objetos de la clase sede y los agregamos al arreglo while ($row = $result->fetch_assoc()) { $row['nombre'] = mb_convert_encoding($row['nombre'], 'UTF-8', mysqli_character_set_name($db)); $nombre = new nombre($row['nombre'], $row['nombre']); array_push($cursos, $nombre); } cerrarConexion($db, $result); // devolvemos el arreglo return $cursos; }
function listar_Todo() { $servername = "localhost"; $username = "******"; $password = "******"; $dbname = "eusa15_bdphp"; $conn = mysqli_connect($servername, $username, $password, $dbname); // Check connection if (!$conn) { echo "Error!"; } if (!mysqli_set_charset($conn, "utf8")) { mysqli_error($conn); } else { mysqli_character_set_name($conn); } $sql = "SELECT centros.nombre as nombre, centros.id as idC, centros.direccion as dir, centros.localidad as loc, centros.telefono as tel FROM centros"; $result = $conn->query($sql); if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { echo "<h2>" . $row["nombre"] . "</h2>" . "<p>Localidad: " . $row["loc"] . "</p>" . "<p>Direccion: " . $row["dir"] . "</p>" . "<p>Telefono: " . $row["tel"] . "</p><br/>"; $n = $row["idC"]; $sql2 = "SELECT MEDICOS.NOMBRE as nombre, MEDICOS.APELLIDOS as apellidos, especialidades.nombre as especialidad, HORARIOS.DIA as dias, HORARIOS.HORARIO as horario from MEDICOS, HORARIOS, especialidades where MEDICOS.ID_ESPECIALIDAD = especialidades.id and MEDICOS.ID_MEDICO=HORARIOS.ID_MEDICO and HORARIOS.ID_CENTRO=" . $n . ""; $result2 = $conn->query($sql2); if ($result2->num_rows > 0) { echo "<table><thead><tr><th>Apellidos</th><th>Nombre</th><th>Especialidad</th><th>Dias</th><th>Horario</th></tr></thead><tbody>"; $bandera = true; while ($row2 = $result2->fetch_assoc()) { if ($bandera) { echo "<tr class='alt'>" . "<td>" . $row2["apellidos"] . "</td>" . "<td>" . $row2["nombre"] . "</td>" . "<td>" . $row2["especialidad"] . "</td>" . "<td>" . $row2["dias"] . "</td>" . "<td>" . $row2["horario"] . "</td>" . "</tr>"; } else { echo "<tr>" . "<td>" . $row2["apellidos"] . "</td>" . "<td>" . $row2["nombre"] . "</td>" . "<td>" . $row2["especialidad"] . "</td>" . "<td>" . $row2["dias"] . "</td>" . "<td>" . $row2["horario"] . "</td>" . "</tr>"; } $bandera = !$bandera; } echo "</tbody></table><br/><br/>"; } } } else { echo "0 results"; } $conn->close(); }
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('_', '-', mysqli_character_set_name(POD::$db)); } if ($client_encoding != 'utf8' && function_exists('iconv')) { $__tcSqlLog[$__tcSqlLogCount]['error'] = iconv($client_encoding, 'utf-8', mysqli_error(POD::$db)); } else { $__tcSqlLog[$__tcSqlLogCount]['error'] = mysqli_error(POD::$db); } $__tcSqlLog[$__tcSqlLogCount]['errno'] = mysqli_errno(POD::$db); 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 && mysqli_errno(POD::$db) == 0) { switch (strtolower(substr($__tcSqlLog[$__tcSqlLogCount]['sql'], 0, 6))) { case 'select': $__tcSqlLog[$__tcSqlLogCount]['rows'] = mysqli_num_rows($result); break; case 'insert': case 'delete': case 'update': $__tcSqlLog[$__tcSqlLogCount]['rows'] = mysqli_affected_rows(POD::$db); break; } } $__tcSqlLogCount++; $__tcSqlQueryBeginTime = 0; }
/** * Is the connection character set equal to utf8? * * @return bool */ public function isConnectionUTF8() { $charset = mysqli_character_set_name($this->_connection); return $charset === 'utf8'; }
function mysql_client_encoding(&$c = null) { if (($c = mysql_global_resource($c, 1 - func_num_args())) == null) { return; } return mysqli_character_set_name($c); }
function mysql_client_encoding(\mysqli $link = null) { return mysqli_character_set_name(\Dshafik\MySQL::getConnection($link)); }
public function getDbInfo() { $charsets = $this->getCharsetInfo(); $charset_str = array(); foreach ($charsets as $name => $value) { $charset_str[] = "{$name} = {$value}"; } return array("MySQLi Version" => @mysqli_get_client_info(), "MySQLi Host Info" => @mysqli_get_host_info($this->database), "MySQLi Server Info" => @mysqli_get_server_info($this->database), "MySQLi Client Encoding" => @mysqli_character_set_name($this->database), "MySQL Character Set Settings" => join(", ", $charset_str)); }
* @platform WebsiteBaker 2.8.x * @version 0.4.1 * @lastmodified August 23, 2016 * */ // Must include code to stop this file being access directly if (defined('WB_PATH') == false) { die("Cannot access this file directly"); } if (is_object($database->DbHandle)) { $title = "MySQLi Info"; $server_info = mysqli_get_server_info($database->DbHandle); $host_info = mysqli_get_host_info($database->DbHandle); $proto_info = mysqli_get_proto_info($database->DbHandle); $client_info = mysqli_get_client_info($database->DbHandle); $client_encoding = mysqli_character_set_name($database->DbHandle); $status = explode(' ', mysqli_stat($database->DbHandle)); } else { $title = "MySQL Info"; $server_info = mysql_get_server_info(); $host_info = mysql_get_host_info(); $proto_info = mysql_get_proto_info(); $client_info = mysql_get_client_info(); $client_encoding = mysql_client_encoding(); $status = explode(' ', mysql_stat()); } $strictMode = $database->get_one('SELECT @@sql_mode'); $strict_info = (strpos($strictMode, 'STRICT_TRANS_TABLES') !== false or strpos($strictMode, 'STRICT_ALL_TABLES') !== false) ? "MySQL strict mode active" : "MySQL strict mode not active\n"; ?> <table cellpadding="3" border="0"> <tbody>
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 }
$_POST['postguid'] = isset($_POST['postguid']) && $_POST['postguid'] == 1 ? 1 : 0; $_POST['fullsearch'] = isset($_POST['fullsearch']) && $_POST['fullsearch'] == 1 ? 1 : 0; $_POST['path_old'] = isset($_POST['path_old']) ? trim($_POST['path_old']) : null; $_POST['path_new'] = isset($_POST['path_new']) ? trim($_POST['path_new']) : null; $_POST['siteurl'] = isset($_POST['siteurl']) ? rtrim(trim($_POST['siteurl']), '/') : null; $_POST['tables'] = isset($_POST['tables']) && is_array($_POST['tables']) ? array_map('stripcslashes', $_POST['tables']) : array(); $_POST['url_old'] = isset($_POST['url_old']) ? trim($_POST['url_old']) : null; $_POST['url_new'] = isset($_POST['url_new']) ? rtrim(trim($_POST['url_new']), '/') : null; //LOGGING $POST_LOG = $_POST; unset($POST_LOG['tables']); unset($POST_LOG['plugins']); unset($POST_LOG['dbpass']); ksort($POST_LOG); $date = @date('h:i:s'); $charset_client = @mysqli_character_set_name($dbh); $log = <<<LOG ******************************************************************************** DUPLICATOR INSTALL-LOG STEP2 START @ {$date} NOTICE: Do not post to public sites or forums ******************************************************************************** CHARSET SERVER:\t{$charset_server} CHARSET CLIENT:\t {$charset_client} LOG; DUPX_Log::Info($log); //Detailed logging
/** * Constructor. * This create an opened connexion to a database server and eventually to a database * * @param string $type Type of database (mysql, pgsql...) * @param string $host Address of database server * @param string $user Nom de l'utilisateur autorise * @param string $pass Mot de passe * @param string $name Nom de la database * @param int $port Port of database server * @return int 1 if OK, 0 if not */ function __construct($type, $host, $user, $pass, $name = '', $port = 0) { global $conf, $langs; // Note that having "static" property for "$forcecharset" and "$forcecollate" will make error here in strict mode, so they are not static 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->database_host = $host; $this->database_port = $port; $this->transaction_opened = 0; //print "Name DB: $host,$user,$pass,$name<br>"; if (!function_exists("mysqli_connect")) { $this->connected = 0; $this->ok = 0; $this->error = "Mysqli PHP functions for using Mysqli driver are not available in this version of PHP. Try to use another driver."; dol_syslog(get_class($this) . "::DoliDBMysqli : Mysqli PHP functions for using Mysqli 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(get_class($this) . "::DoliDBMysqli : Erreur Connect, wrong host parameters", LOG_ERR); return $this->ok; } // Essai connexion serveur // We do not try to connect to database, only to server. Connect to database is done later in constrcutor $this->db = $this->connect($host, $user, $pass, '', $port); if ($this->db) { $this->connected = 1; $this->ok = 1; } else { // host, login ou password incorrect $this->connected = 0; $this->ok = 0; $this->error = mysqli_connect_error(); dol_syslog(get_class($this) . "::DoliDBMysqli : Erreur Connect mysqli_connect_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 (mysqli_character_set_name($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(get_class($this) . "::DoliDBMysqli : 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 (mysqli_character_set_name($this->db) != $clientmustbe) { $this->query("SET NAMES '" . $clientmustbe . "'", $this->db); //$this->query("SET CHARACTER SET ". $this->forcecharset); } } } return $this->ok; }
$CustSDR = $_POST['CustSDR']; $Amt = $_POST['Amt']; $Notes = $_POST['Notes']; $N2 = $_POST['Notes2']; $N3 = $_POST['Notes3']; $N4 = $_POST['Notes4']; $N5 = $_POST['Notes5']; $N6 = $_POST['Notes6']; $N7 = $_POST['Notes7']; $N8 = $_POST['Notes8']; $Notes = $Notes + $N2 + $N3 + $N4 + $N5 + $N6 + $N7 + $N8; $EEmail = $Notes; echo " notes:" . $Notes; //$str = htmlentities('$Notes'); //causes a blank! //$Notes = htmlspecialchars($Notes); $charset = mysqli_character_set_name($DBConnect); printf("Current character set is %s\n", $charset); //$Notes = htmlspecialchars("$Notes", ENT_QUOTES); //header( "Content-Type: text/html; charset=utf-8" ); /*$body = "begrüßen zu dürfen"; $g = "ben zu fen"; echo htmlentities( $body ); echo htmlentities( $g ); */ /*htmlXspecialchars($Notes); htmlXentities($Notes); htmlX_entity_decode($Notes); */ $Notes = str_replace('"', '"', $Notes); //for mailto: emails. $EEmail = $Notes;
if ($Connect) { if (version_compare(ereg_replace("-.*\$", "", mysqli_get_server_info($mysqli)), '4.1.1') < 0) { $result = mysqli_query($mysqli, "SHOW VARIABLES LIKE 'character_set';", MYSQLI_USE_RESULT); if ($Row = mysqli_fetch_array($result)) { $_SESSION['charset'] = $Row['Value']; } mysqli_free_result($result); } else { if (version_compare(phpversion(), '5.2.3') < 0 || version_compare(ereg_replace("-.*\$", "", mysqli_get_server_info($mysqli)), '5.0.7')) { $result = mysqli_query($mysqli, "SHOW VARIABLES LIKE 'character_set_client';", MYSQLI_USE_RESULT); if ($Row = mysqli_fetch_array($result)) { $_SESSION['charset'] = $Row['Value']; } mysqli_free_result($result); } else { $_SESSION['charset'] = mysqli_character_set_name($mysqli); } } if (version_compare(ereg_replace("-.*\$", "", mysqli_get_server_info($mysqli)), '4.1.1') < 0) { $CharsetNr = $Charsets[$_SESSION['charset']]; } else { if (version_compare(ereg_replace("-.*\$", "", mysqli_get_server_info($mysqli)), '5.0.0') < 0) { $result = mysqli_query($mysqli, 'SHOW COLLATION;', MYSQLI_USE_RESULT); while ($Row = mysqli_fetch_array($result)) { if ($Row['Charset'] == $_SESSION['charset'] && $Row['Default'] == 'Yes') { $CharsetNr = (int) $Row['Id']; } } mysqli_free_result($result); } else { $result = mysqli_query($mysqli, "SHOW COLLATION WHERE `Charset`='" . $_SESSION['charset'] . "' AND `Default`='Yes';", MYSQLI_USE_RESULT);
function cs_sql_version($cs_file) { global $cs_db; $subtype = empty($cs_db['subtype']) ? 'myisam' : strtolower($cs_db['subtype']); $sql_infos = array('data_free' => 0, 'data_size' => 0, 'index_size' => 0, 'tables' => 0, 'names' => array()); $sql_query = "SHOW TABLE STATUS LIKE '" . cs_sql_escape($cs_db['prefix'] . '_') . "%'"; $sql_data = mysqli_query($cs_db['con'], $sql_query) or cs_error_sql($cs_file, 'cs_sql_version', cs_sql_error(0, $sql_query)); while ($row = mysqli_fetch_assoc($sql_data)) { $sql_infos['data_size'] += $row['Data_length']; $sql_infos['index_size'] += $row['Index_length']; $sql_infos['data_free'] += $subtype == 'innodb' ? 0 : $row['Data_free']; $sql_infos['tables']++; $sql_infos['names'][] .= $row['Name']; } mysqli_free_result($sql_data); cs_log_sql($cs_file, $sql_query); $sql_infos['encoding'] = mysqli_character_set_name($cs_db['con']); $sql_infos['type'] = 'MySQL (mysqli)'; $sql_infos['subtype'] = empty($cs_db['subtype']) ? 'myisam' : $cs_db['subtype']; $sql_infos['client'] = mysqli_get_client_info(); $sql_infos['host'] = mysqli_get_host_info($cs_db['con']) or cs_error_sql($cs_file, 'cs_sql_version', cs_sql_error()); $sql_infos['server'] = mysqli_get_server_info($cs_db['con']) or cs_error_sql($cs_file, 'cs_sql_version', cs_sql_error()); return $sql_infos; }
printf("[007] Need MySQL Server 4.1+ for the test!\n"); } if (!($res = mysqli_query($link, 'SELECT @@character_set_connection AS charset, @@collation_connection AS collation'))) { printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); } $tmp = mysqli_fetch_assoc($res); mysqli_free_result($res); if (!$tmp['charset']) { printf("[009] Cannot determine current character set and collation\n"); } $charset = mysqli_character_set_name($link); if ($tmp['charset'] !== $charset) { if ($tmp['collation'] === $charset) { printf("[010] Could be known server bug http://bugs.mysql.com/bug.php?id=7923, collation %s instead of character set returned, expected string/%s, got %s/%s\n", $tmp['collation'], $tmp['charset'], gettype($charset), $charset); } else { printf("[011] Expecting character set %s/%s, got %s/%s\n", gettype($tmp['charset']), $tmp['charset'], gettype($charset), $charset); } } $charset2 = mysqli_character_set_name($link); if ($charset2 !== $charset) { printf("[012] Alias mysqli_character_set_name returned %s/%s, expected %s/%s\n", gettype($charset2), $charset2, gettype($charset), $charset); } mysqli_close($link); if (NULL !== ($tmp = @mysqli_character_set_name($link))) { printf("[013] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); } /* Make sure that the function alias exists */ if (!is_null($tmp = @mysqli_character_set_name())) { printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); } print "done!";
} } // maximum length for a category in this database $category_strlen_max = zen_field_length(TABLE_CATEGORIES_DESCRIPTION, 'categories_name'); // maximum length for important fields $categories_name_max_len = zen_field_length(TABLE_CATEGORIES_DESCRIPTION, 'categories_name'); $manufacturers_name_max_len = zen_field_length(TABLE_MANUFACTURERS, 'manufacturers_name'); $products_model_max_len = zen_field_length(TABLE_PRODUCTS, 'products_model'); $products_name_max_len = zen_field_length(TABLE_PRODUCTS_DESCRIPTION, 'products_name'); $products_url_max_len = zen_field_length(TABLE_PRODUCTS_DESCRIPTION, 'products_url'); $artists_name_max_len = zen_field_length(TABLE_RECORD_ARTISTS, 'artists_name'); $record_company_name_max_len = zen_field_length(TABLE_RECORD_COMPANY, 'record_company_name'); $music_genre_name_max_len = zen_field_length(TABLE_MUSIC_GENRE, 'music_genre_name'); $project = PROJECT_VERSION_MAJOR . '.' . PROJECT_VERSION_MINOR; if ($ep_uses_mysqli) { $collation = mysqli_character_set_name($db->link); // should be either latin1 or utf8 } else { $collation = mysql_client_encoding(); // should be either latin1 or utf8 } if ($collation == 'utf8') { mb_internal_encoding("UTF-8"); } if ($collation == 'utf8' && (substr($project, 0, 5) == "1.3.8" || substr($project, 0, 5) == "1.3.9")) { //mb_internal_encoding("UTF-8"); $category_strlen_max = $category_strlen_max / 3; $categories_name_max_len = $categories_name_max_len / 3; $manufacturers_name_max_len = $manufacturers_name_max_len / 3; $products_model_max_len = $products_model_max_len / 3; $products_name_max_len = $products_name_max_len / 3;
<?php //echo '<head> <meta http-equiv="Refresh" content="2;url=http://172.16.123.3"> </head>'; include_once "includes/sql_connect.php"; include_once "functions"; include_once "includes/jQuery.js"; echo '<head><script type="text/javascript"> $(document).ready(function(){ $("#test").click(function(){ alert("fatgai"); }); });</script></head>'; //redirect("login.php"); echo $_COOKIE['username']; echo $_COOKIE['pass']; echo check_login($mysql, 'hao', '123456'); echo '<p id="test">hehehheehehehehe</p>'; echo mysqli_character_set_name($mysql); //var_dump($_SERVER); //echo '<script language="javascript"> url = window.location.href="http://172.16.122.8/login.php"</script>'; //echo '<head> <meta http-equiv="Refresh" content="2;url=http://172.16.123.3"> </head>'; //把网址代换 window.navigate(url);
<?php require_once "connect.inc"; /*** test mysqli_connect 127.0.0.1 ***/ $link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket); $cset = substr(mysqli_character_set_name($link), 0, 6); var_dump($cset); mysqli_close($link); print "done!";
/** * debuger * * @param boolean $log2file * @param mixed $debugFile */ public function debug($log2file = false, $debugFile = false) { if ($log2file == 'off') { if (is_object($this->debug)) { $this->debug->getLog(); $this->debug = false; } } else { $debugFile = $debugFile ?: (defined('DALMP_DEBUG_FILE') ? DALMP_DEBUG_FILE : '/tmp/dalmp.log'); $this->debug = new Logger($log2file, $debugFile); $this->debug->log('DSN', $this->dsn); if ($this->isConnected()) { $this->debug->log('DALMP', mysqli_get_host_info($this->DB), 'protocol version: ' . mysqli_get_proto_info($this->DB), 'character set: ' . mysqli_character_set_name($this->DB)); } } return; }
mysqli_free_result($res); $version = explode('.', $tmp['server_version']); if (empty($version)) { printf("[006] Cannot determine server version, need MySQL Server 4.1+ for the test!\n"); } if ($version[0] <= 4 && $version[1] < 1) { printf("[007] Need MySQL Server 4.1+ for the test!\n"); } if (!($res = mysqli_query($link, 'SELECT @@character_set_connection AS charset, @@collation_connection AS collation'))) { printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); } $tmp = mysqli_fetch_assoc($res); mysqli_free_result($res); if (!$tmp['charset']) { printf("[009] Cannot determine current character set and collation\n"); } $charset = mysqli_character_set_name($link); if ($tmp['charset'] !== $charset) { if ($tmp['collation'] === $charset) { printf("[010] Could be known server bug http://bugs.mysql.com/bug.php?id=7923, collation %s instead of character set returned, expected string/%s, got %s/%s\n", $tmp['collation'], $tmp['charset'], gettype($charset), $charset); } else { printf("[011] Expecting character set %s/%s, got %s/%s\n", gettype($tmp['charset']), $tmp['charset'], gettype($charset), $charset); } } $charset2 = mysqli_character_set_name($link); if ($charset2 !== $charset) { printf("[012] Alias mysqli_character_set_name returned %s/%s, expected %s/%s\n", gettype($charset2), $charset2, gettype($charset), $charset); } mysqli_close($link); /* Make sure that the function alias exists */ print "done!";
echo $result; ?> </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 . "  " . str_replace("%encoding", $encoding, $lang["client-encoding"]); ?> </td><td><b><?php echo $result; ?> </b></td></tr><?php # Check GD installed
<?php include "../config.php"; session_start(); // si se está enviando por POST el id del país // significa que intentamos acceder desde jQuery if (isset($_POST['id'])) { $numeros_equipos = array(); $sql = "SELECT * \n FROM operaciones_numero_equipo\n WHERE id_equipo = " . $_POST['id'] . " ORDER BY numero ASC"; $link = Conectarse(); // obtenemos todos los países $result = mysqli_query($link, $sql); // creamos objetos de la clase ciudad y los agregamos al arreglo while ($row = $result->fetch_assoc()) { $row['numero'] = mb_convert_encoding($row['numero'], 'UTF-8', mysqli_character_set_name($link)); $numero_equipo = new numero_equipo($row['id'], $row['numero']); array_push($numeros_equipos, $numero_equipo); } // devolvemos el arreglo de ciudades, en formato JSON echo json_encode($numeros_equipos); } class numero_equipo { public $id; public $numero; function __construct($id, $numero) { $this->id = $id; $this->numero = $numero; } }
$_POST['url_old'] = isset($_POST['url_old']) ? trim($_POST['url_old']) : null; $_POST['url_new'] = isset($_POST['url_new']) ? rtrim(trim($_POST['url_new']), '/') : null; //LOGGING $POST_LOG = $_POST; unset($POST_LOG['tables']); unset($POST_LOG['plugins']); unset($POST_LOG['dbpass']); ksort($POST_LOG); //GLOBAL DB-REPLACE DupUtil::log("\n\n\n{$GLOBALS['SEPERATOR1']}"); DupUtil::log('DUPLICATOR INSTALL-LOG'); DupUtil::log('STEP2 START @ ' . @date('h:i:s')); DupUtil::log('NOTICE: NOTICE: Do not post to public sites or forums'); DupUtil::log("{$GLOBALS['SEPERATOR1']}"); DupUtil::log("CHARSET SERVER:\t{$charset_server}"); DupUtil::log("CHARSET CLIENT:\t" . @mysqli_character_set_name($dbh)); DupUtil::log("--------------------------------------"); DupUtil::log("POST DATA"); DupUtil::log("--------------------------------------"); DupUtil::log(print_r($POST_LOG, true)); DupUtil::log("--------------------------------------"); DupUtil::log("SCANNED TABLES"); DupUtil::log("--------------------------------------"); $msg = isset($_POST['tables']) && count($_POST['tables'] > 0) ? print_r($_POST['tables'], true) : 'No tables selected to update'; DupUtil::log($msg); DupUtil::log("--------------------------------------"); DupUtil::log("KEEP PLUGINS ACTIVE"); DupUtil::log("--------------------------------------"); $msg = isset($_POST['plugins']) && count($_POST['plugins'] > 0) ? print_r($_POST['plugins'], true) : 'No plugins selected for activation'; DupUtil::log($msg); //UPDATE SETTINGS
/** * 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; }
<?php ini_set("display_errors", On); error_reporting(E_ALL); mb_language("uni"); mb_internal_encoding("utf-8"); mb_http_input("auto"); mb_http_output("utf-8"); require "constant.php"; $cont_id = $_POST['contribution_id']; $reaction = $_POST['text']; $user_id = $_POST['user_id']; //$sql = "INSERT INTO user (name, facebook_id, img, univ, grad_year) VALUES('$name', $fb_id, '$img', '$univ', $grad_year)"; $sql = "INSERT INTO reaction (cont_id, reaction, user_id, created_at) VALUES({$cont_id}, '{$reaction}', {$user_id}, now())"; $link = new mysqli("localhost", "{$db_usr}", "{$db_pwd}", "{$db_name}"); if (!mysqli_set_charset($link, "utf8")) { printf("Error loading character set utf8: %s\n", mysqli_error($link)); } else { printf("Current character set: %s\n", mysqli_character_set_name($link)); } if ($link->query($sql)) { } else { if (mysqli_connect_errno()) { printf("connect failed: %s\n", $link->connect_error()); exit; } } mysqli_close($link);
function mysql_compat_client_encoding($link = NULL) { if (!isset($link)) { $link = $GLOBALS['mysql_compat_last_link']; } return mysqli_character_set_name($link); }