Commit 3ef69309 authored by Gábor Hojtsy's avatar Gábor Hojtsy

#772678 by sun, jpmckinney, Berdir, markus_petrux: no way to specify default...

#772678 by sun, jpmckinney, Berdir, markus_petrux: no way to specify default collation, entirely depended on database configuration (which might be inappropriate)
parent c7528ebb
......@@ -376,7 +376,7 @@ function conf_init() {
global $base_url, $base_path, $base_root;
// Export the following settings.php variables to the global namespace
global $db_url, $db_prefix, $cookie_domain, $conf, $installed_profile, $update_free_access;
global $db_url, $db_prefix, $db_collation, $cookie_domain, $conf, $installed_profile, $update_free_access;
$conf = array();
if (isset($_SERVER['HTTP_HOST'])) {
......
......@@ -60,7 +60,16 @@ function db_query($query) {
function db_create_table_sql($name, $table) {
if (empty($table['mysql_suffix'])) {
$table['mysql_suffix'] = "/*!40100 DEFAULT CHARACTER SET UTF8 */";
$table['mysql_suffix'] = '/*!40100 DEFAULT CHARACTER SET utf8';
// By default, MySQL uses the default collation for new tables, which is
// 'utf8_general_ci' for utf8. If an alternate collation has been set, it
// needs to be explicitly specified.
// @see db_connect()
$collation = (!empty($table['collation']) ? $table['collation'] : (!empty($GLOBALS['db_collation']) ? $GLOBALS['db_collation'] : ''));
if ($collation) {
$table['mysql_suffix'] .= ' COLLATE ' . $collation;
}
$table['mysql_suffix'] .= ' */';
}
$sql = "CREATE TABLE {". $name ."} (\n";
......
......@@ -80,8 +80,16 @@ function db_connect($url) {
_db_error_page(mysql_error());
}
// Force UTF-8.
mysql_query('SET NAMES "utf8"', $connection);
// Force MySQL to use the UTF-8 character set. Also set the collation, if a
// certain one has been set; otherwise, MySQL defaults to 'utf8_general_ci'
// for UTF-8.
if (!empty($GLOBALS['db_collation'])) {
mysql_query('SET NAMES utf8 COLLATE '. $GLOBALS['db_collation'], $connection);
}
else {
mysql_query('SET NAMES utf8', $connection);
}
return $connection;
}
......
......@@ -79,8 +79,15 @@ function db_connect($url) {
_db_error_page(mysqli_connect_error());
}
// Force UTF-8.
mysqli_query($connection, 'SET NAMES "utf8"');
// Force MySQL to use the UTF-8 character set. Also set the collation, if a
// certain one has been set; otherwise, MySQL defaults to 'utf8_general_ci'
// for UTF-8.
if (!empty($GLOBALS['db_collation'])) {
mysqli_query($connection, 'SET NAMES utf8 COLLATE ' . $GLOBALS['db_collation']);
}
else {
mysqli_query($connection, 'SET NAMES utf8');
}
return $connection;
}
......
......@@ -92,6 +92,26 @@
$db_url = 'mysql://username:password@localhost/databasename';
$db_prefix = '';
/**
* Database default collation.
*
* All data stored in Drupal is in UTF-8. Certain databases, such as MySQL,
* support different algorithms for comparing, indexing, and sorting characters;
* a so called "collation". The default collation of a database normally works
* for many use-cases, but depending on the language(s) of the stored data, it
* may be necessary to use a different collation.
* Important:
* - Only set or change this value BEFORE installing Drupal, unless you know
* what you are doing.
* - All database tables and columns should be in the same collation. Otherwise,
* string comparisons performed for table JOINs will be significantly slower.
* - Especially when storing data in German or Russian on MySQL 5.1+, you want
* to use the 'utf8_unicode_ci' collation instead.
*
* @see http://drupal.org/node/772678
*/
# $db_collation = 'utf8_general_ci';
/**
* Access control for update.php script
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment