Skip to content
Permalink
Browse files

Use InnoDB and utf8mb4 on current mysql databases

For new installations only so far
  • Loading branch information
onli committed Mar 22, 2020
1 parent 05fe0a3 commit b15a453165189091a61ea3953da285b6f2c84d8e
Showing with 37 additions and 6 deletions.
  1. +5 −0 docs/NEWS
  2. +32 −6 include/db/mysqli.inc.php
@@ -1,6 +1,11 @@
Version 2.4-alpha1 ()
------------------------------------------------------------------------

* Switch new installations with MySQL >= 5.6.4 or MariaDB >= 10.0.5
to the InooDB stoprage engine and utf8mb4 charset. This enables
proper unicode support plus fulltext indexes, something older
mysql databases were not capable of

* Plugin nl2br: Include figure and figcaption tags (2.21.3)
Thanks to @stephanbrunker!

@@ -247,12 +247,16 @@ function serendipity_db_connect() {
function serendipity_db_reconnect() {
global $serendipity;

if (isset($serendipity['dbCharset'])) {
mysqli_set_charset($serendipity['dbConn'], $serendipity['dbCharset']);
if (isset($serendipity['dbCharset']) && !empty($serendipity['dbCharset'])) {
$use_charset = $serendipity['dbCharset'];
@define('SQL_CHARSET_INIT', true);
} elseif (defined('SQL_CHARSET') && $serendipity['dbNames'] && !defined('SQL_CHARSET_INIT')) {
mysqli_set_charset($serendipity['dbConn'], SQL_CHARSET);
$use_charset = SQL_CHARSET;
} else {
$use_charset = 'utf8';
}

mysqli_set_charset($serendipity['dbConn'], $use_charset);
}

/**
@@ -269,20 +273,42 @@ function serendipity_db_schema_import($query) {
'unsigned' , 'FULLTEXT', 'FULLTEXT', 'enum (\'true\', \'false\') NOT NULL default \'true\'', 'LONGTEXT');
static $is_utf8 = null;
global $serendipity;

$mysql_version = mysqli_get_server_info($serendipity['dbConn']);
$maria = false;
if (strpos($mysql_version, 'MariaDB') !== false) {
$maria = true;
}
if ($maria) {
# maria trips up our version detection scheme by prepending 5.5.5 to newer versions
$mysql_version = str_replace('5.5.5-', '', $mysql_version);
}

if ($is_utf8 === null) {
$search[] = '{UTF_8}';
if ( $_POST['charset'] == 'UTF-8/' ||
$serendipity['charset'] == 'UTF-8/' ||
$serendipity['POST']['charset'] == 'UTF-8/' ||
LANG_CHARSET == 'UTF-8' ) {
$replace[] = '/*!40100 CHARACTER SET utf8 COLLATE utf8_unicode_ci */';
if ((version_compare($mysql_version, '10.0.5', '>=') && $maria) || ((! $maria) && version_compare($mysql_version, '5.6.4', '>='))) {
$replace[] = '/*!40100 CHARACTER SET utf8 COLLATE utf8mb4_unicode_ci */';
} else {
# in old versions we stick to the three byte pseudo utf8 to not trip
# over the max index restriction of 1000 bytes
$replace[] = '/*!40100 CHARACTER SET utf8 COLLATE utf8_unicode_ci */';
}
} else {
$replace[] = '';
}
}

serendipity_db_query("SET storage_engine=MYISAM");
if ((version_compare($mysql_version, '10.0.5', '>=') && $maria) || ((! $maria) && version_compare($mysql_version, '5.6.4', '>='))) {
# InnoDB enables us to use utf8mb4 with the higher max index size
serendipity_db_query("SET storage_engine=INNODB");
} else {
# Before 5.6.4/10.0.5 InnoDB did not support fulltext indexes, which we use,
# thus we stay with MyISAM here
serendipity_db_query("SET storage_engine=MYISAM");
}

$query = trim(str_replace($search, $replace, $query));
if ($query[0] == '@') {

0 comments on commit b15a453

Please sign in to comment.
You can’t perform that action at this time.