php
/**
* MySQL + PHP 8.x Compatibility Shim v4
* Map mysql_* → mysqli_* + Fix PHP 8.x breaking changes
* Cho CMS Erasoft chay tren PHP 8.0/8.1/8.2
*/
// === PHP 8.x: Suppress errors + fix breaking functions ===
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING & ~E_DEPRECATED & ~E_STRICT);
// PHP 8.0+: count(null) throws TypeError → override
if (PHP_VERSION_ID >= 80000) {
// Wrap problematic built-in functions for PHP 8.x
// Override: utf8_encode/utf8_decode removed in PHP 8.2
if (!function_exists('utf8_encode')) {
function utf8_encode($string) {
return mb_convert_encoding($string, 'UTF-8', 'ISO-8859-1');
}
}
if (!function_exists('utf8_decode')) {
function utf8_decode($string) {
return mb_convert_encoding($string, 'ISO-8859-1', 'UTF-8');
}
}
}
// === MySQL Compatibility Layer ===
if (!function_exists('mysql_connect')) {
$GLOBALS['__mysql_compat_link'] = null;
$GLOBALS['__mysql_compat_last_error'] = '';
$GLOBALS['__mysql_compat_last_errno'] = 0;
function mysql_connect($server = null, $username = null, $password = null) {
$port = 3306;
if ($server && strpos($server, ':') !== false) {
$parts = explode(':', $server);
$server = $parts[0];
$port = intval($parts[1]);
}
if ($server === 'localhost' || $server === '') {
$server = '127.0.0.1';
}
$link = @mysqli_connect($server, $username, $password, '', $port);
if ($link) {
$GLOBALS['__mysql_compat_link'] = $link;
@mysqli_set_charset($link, 'utf8');
$GLOBALS['__mysql_compat_last_error'] = '';
$GLOBALS['__mysql_compat_last_errno'] = 0;
return $link;
}
$GLOBALS['__mysql_compat_last_error'] = mysqli_connect_error();
$GLOBALS['__mysql_compat_last_errno'] = mysqli_connect_errno();
return false;
}
function mysql_pconnect($server = null, $username = null, $password = null) {
$port = 3306;
if ($server && strpos($server, ':') !== false) {
$parts = explode(':', $server);
$server = $parts[0];
$port = intval($parts[1]);
}
if ($server === 'localhost' || $server === '') {
$server = '127.0.0.1';
}
$link = @mysqli_connect($server, $username, $password, '', $port);
if ($link) {
$GLOBALS['__mysql_compat_link'] = $link;
@mysqli_set_charset($link, 'utf8');
$GLOBALS['__mysql_compat_last_error'] = '';
$GLOBALS['__mysql_compat_last_errno'] = 0;
return $link;
}
$GLOBALS['__mysql_compat_last_error'] = mysqli_connect_error();
$GLOBALS['__mysql_compat_last_errno'] = mysqli_connect_errno();
return false;
}
function mysql_select_db($database_name, $link = null) {
$link = $link ?: $GLOBALS['__mysql_compat_link'];
if (!$link) return false;
$result = @mysqli_select_db($link, $database_name);
if (!$result) {
$GLOBALS['__mysql_compat_last_error'] = mysqli_error($link);
$GLOBALS['__mysql_compat_last_errno'] = mysqli_errno($link);
}
return $result;
}
function mysql_query($query, $link = null) {
$link = $link ?: $GLOBALS['__mysql_compat_link'];
if (!$link) return false;
$result = @mysqli_query($link, $query);
if ($result === false) {
$GLOBALS['__mysql_compat_last_error'] = mysqli_error($link);
$GLOBALS['__mysql_compat_last_errno'] = mysqli_errno($link);
}
return $result;
}
function mysql_unbuffered_query($query, $link = null) {
$link = $link ?: $GLOBALS['__mysql_compat_link'];
if (!$link) return false;
return @mysqli_query($link, $query, MYSQLI_USE_RESULT);
}
function mysql_fetch_array($result, $result_type = MYSQLI_BOTH) {
if (!$result) return null;
return @mysqli_fetch_array($result, $result_type);
}
function mysql_fetch_assoc($result) {
if (!$result) return null;
return @mysqli_fetch_assoc($result);
}
function mysql_fetch_row($result) {
if (!$result) return null;
return @mysqli_fetch_row($result);
}
function mysql_fetch_object($result) {
if (!$result) return null;
return @mysqli_fetch_object($result);
}
function mysql_num_rows($result) {
if (!$result) return 0;
return @mysqli_num_rows($result);
}
function mysql_num_fields($result) {
if (!$result) return 0;
return @mysqli_num_fields($result);
}
function mysql_affected_rows($link = null) {
$link = $link ?: $GLOBALS['__mysql_compat_link'];
if (!$link) return -1;
return mysqli_affected_rows($link);
}
function mysql_insert_id($link = null) {
$link = $link ?: $GLOBALS['__mysql_compat_link'];
if (!$link) return 0;
return mysqli_insert_id($link);
}
function mysql_real_escape_string($string, $link = null) {
$link = $link ?: $GLOBALS['__mysql_compat_link'];
if (!$link) return addslashes($string ?: '');
return mysqli_real_escape_string($link, $string ?: '');
}
function mysql_escape_string($string) {
$link = $GLOBALS['__mysql_compat_link'];
if (!$link) return addslashes($string ?: '');
return mysqli_real_escape_string($link, $string ?: '');
}
function mysql_close($link = null) {
$link = $link ?: $GLOBALS['__mysql_compat_link'];
if (!$link) return false;
$result = @mysqli_close($link);
if ($link === $GLOBALS['__mysql_compat_link']) {
$GLOBALS['__mysql_compat_link'] = null;
}
return $result;
}
function mysql_error($link = null) {
$link = $link ?: $GLOBALS['__mysql_compat_link'];
if (!$link) return $GLOBALS['__mysql_compat_last_error'];
return mysqli_error($link);
}
function mysql_errno($link = null) {
$link = $link ?: $GLOBALS['__mysql_compat_link'];
if (!$link) return $GLOBALS['__mysql_compat_last_errno'];
return mysqli_errno($link);
}
function mysql_free_result($result) {
if (!$result) return false;
@mysqli_free_result($result);
return true;
}
function mysql_data_seek($result, $row_number) {
if (!$result) return false;
return @mysqli_data_seek($result, $row_number);
}
function mysql_result($result, $row, $field = 0) {
if (!$result) return false;
@mysqli_data_seek($result, $row);
$row_data = @mysqli_fetch_array($result);
return isset($row_data[$field]) ? $row_data[$field] : false;
}
function mysql_field_name($result, $field_offset) {
if (!$result) return false;
$info = @mysqli_fetch_field_direct($result, $field_offset);
return $info ? $info->name : false;
}
function mysql_field_type($result, $field_offset) {
if (!$result) return false;
$info = @mysqli_fetch_field_direct($result, $field_offset);
return $info ? $info->type : false;
}
function mysql_field_len($result, $field_offset) {
if (!$result) return false;
$info = @mysqli_fetch_field_direct($result, $field_offset);
return $info ? $info->length : false;
}
function mysql_fetch_lengths($result) {
if (!$result) return false;
return @mysqli_fetch_lengths($result);
}
function mysql_info($link = null) {
$link = $link ?: $GLOBALS['__mysql_compat_link'];
if (!$link) return false;
return @mysqli_info($link);
}
function mysql_list_dbs($link = null) {
$link = $link ?: $GLOBALS['__mysql_compat_link'];
if (!$link) return false;
return @mysqli_query($link, "SHOW DATABASES");
}
function mysql_list_tables($database, $link = null) {
$link = $link ?: $GLOBALS['__mysql_compat_link'];
if (!$link) return false;
return @mysqli_query($link, "SHOW TABLES FROM `" . mysqli_real_escape_string($link, $database) . "`");
}
function mysql_tablename($result, $i) {
if (!$result) return false;
@mysqli_data_seek($result, $i);
$row = @mysqli_fetch_row($result);
return $row ? $row[0] : false;
}
function mysql_get_server_info($link = null) {
$link = $link ?: $GLOBALS['__mysql_compat_link'];
if (!$link) return false;
return mysqli_get_server_info($link);
}
function mysql_get_client_info() {
return mysqli_get_client_info();
}
function mysql_get_host_info($link = null) {
$link = $link ?: $GLOBALS['__mysql_compat_link'];
if (!$link) return false;
return mysqli_get_host_info($link);
}
function mysql_get_proto_info($link = null) {
$link = $link ?: $GLOBALS['__mysql_compat_link'];
if (!$link) return false;
return mysqli_get_proto_info($link);
}
function mysql_ping($link = null) {
$link = $link ?: $GLOBALS['__mysql_compat_link'];
if (!$link) return false;
return @mysqli_ping($link);
}
function mysql_stat($link = null) {
$link = $link ?: $GLOBALS['__mysql_compat_link'];
if (!$link) return false;
return @mysqli_stat($link);
}
function mysql_thread_id($link = null) {
$link = $link ?: $GLOBALS['__mysql_compat_link'];
if (!$link) return 0;
return mysqli_thread_id($link);
}
function mysql_set_charset($charset, $link = null) {
$link = $link ?: $GLOBALS['__mysql_compat_link'];
if (!$link) return false;
return @mysqli_set_charset($link, $charset);
}
// Constants
if (!defined('MYSQL_ASSOC')) define('MYSQL_ASSOC', MYSQLI_ASSOC);
if (!defined('MYSQL_NUM')) define('MYSQL_NUM', MYSQLI_NUM);
if (!defined('MYSQL_BOTH')) define('MYSQL_BOTH', MYSQLI_BOTH);
if (!defined('MYSQL_CLIENT_COMPRESS')) define('MYSQL_CLIENT_COMPRESS', MYSQLI_CLIENT_COMPRESS);
if (!defined('MYSQL_CLIENT_IGNORE_SPACE')) define('MYSQL_CLIENT_IGNORE_SPACE', MYSQLI_CLIENT_IGNORE_SPACE);
if (!defined('MYSQL_CLIENT_INTERACTIVE')) define('MYSQL_CLIENT_INTERACTIVE', MYSQLI_CLIENT_INTERACTIVE);
if (!defined('MYSQL_CLIENT_SSL')) define('MYSQL_CLIENT_SSL', MYSQLI_CLIENT_SSL);
}
function ngocviet_lazy($h){
$n=0;$h=preg_replace_callback('/
]*)>/i',function($m)use(&$n){
$n++;$a=$m[1];
if(!preg_match('/width\s*=/i',$a)){$w=400;$ht=300;
if(preg_match('/src=["\x27]([^"\x27]+)/i',$a,$s)){
$p=dirname(__FILE__).'/'.ltrim(parse_url($s[1],PHP_URL_PATH),'/');
if(file_exists($p)){$sz=@getimagesize($p);if($sz){$w=$sz[0];$ht=$sz[1];}}}
$a.=' width="'.$w.'" height="'.$ht.'" style="aspect-ratio:'.$w.'/'.$ht.';max-width:100%;height:auto"';}
if($n>3&&stripos($a,'loading=')===false)$a.=' loading="lazy" decoding="async"';
return '
';
},$h);return $h;}
ob_start('ngocviet_lazy');
Fatal error: Uncaught Error: Call to undefined function mysql_pconnect() in /home/ngocviet/public_html/inc/config_start.php:26
Stack trace:
#0 /home/ngocviet/public_html/inc/start.php(9): require()
#1 /home/ngocviet/public_html/index.php(4): require_once('/home/ngocviet/...')
#2 {main}
thrown in /home/ngocviet/public_html/inc/config_start.php on line 26