代码片段
<?php
/**
* Emlog emoji表情支持 升级补丁
*
* 将此文件放到Emlog根目录下执行一次即可
* 需要MySQL版本 >= 5.5
*
* AXuan
* https://blog.yxbug.cn/
* 2021/02/20
*/
require 'config.php';
define('DS', DIRECTORY_SEPARATOR);
$db = new mysqli(DB_HOST, DB_USER, DB_PASSWD, DB_NAME);
$db->set_charset('utf8');
$sql = "SELECT VERSION()";
$query = $db->query($sql)->fetch_array(MYSQLI_NUM);
$version = $query[0];
if (version_compare($version, '5.5.0') < 0) {
echo "Need mysql >= 5.5.0";
exit();
}
$column_list = array(
'blog' => array(
array('title', 'varchar(255)'),
array('content', 'longtext'),
array('excerpt', 'longtext')
),
'comment' => array(
array('poster', 'varchar(20)'),
array('comment', 'text')
),
'twitter' => array(
array('content', 'text')
),
'reply' => array(
array('name', 'varchar(20)'),
array('content', 'text')
),
/* 如果使用 YXMarkDown插件可去除注释
'yxmd' => array(
array('content','text')
)
*/
);
foreach ($column_list as $key => $value) {
$table_name = DB_PREFIX . $key;
foreach ($value as $column) {
$sql = "ALTER TABLE `{$table_name}` MODIFY `{$column[0]}` {$column[1]} CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci";
$db->query($sql);
echo "Update {$table_name} -> {$column[0]}<br />\r\n";
}
}
$mysql_lib = dirname(__FILE__) . DS . 'include' . DS . 'lib' . DS. 'mysql.php';
$mysql_content = file_get_contents($mysql_lib);
$mysql_content = str_replace("SET NAMES 'utf8'", "SET NAMES 'utf8mb4'", $mysql_content);
file_put_contents($mysql_lib, $mysql_content);
echo "Update mysql lib<br />\r\n";
$mysqli_lib = dirname(__FILE__) . DS . 'include' . DS . 'lib' . DS. 'mysqlii.php';
$mysqli_content = file_get_contents($mysqli_lib);
$mysqli_content = str_replace("set_charset('utf8')", "set_charset('utf8mb4')", $mysqli_content);
file_put_contents($mysqli_lib, $mysqli_content);
echo "Update mysqli lib<br />\r\n";
echo "Done";
?>
emlog6.0.1可以升级支持吗?