First cut at mysql utf-8 charset suport. Props to sehh, drupal, and textpattern. fixes #3517

git-svn-id: http://svn.automattic.com/wordpress/trunk@4860 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2007-02-02 00:04:35 +00:00
parent af10b7443f
commit ce0f8b4a66
4 changed files with 35 additions and 12 deletions

View File

@ -1,6 +1,15 @@
<?php
// Here we keep the DB structure and option values
$charset_collate = '';
if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') ) {
if ( ! empty($wpdb->charset) )
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
if ( ! empty($wpdb->collate) )
$charset_collate .= " COLLATE $wpdb->collate";
}
$wp_queries="CREATE TABLE $wpdb->categories (
cat_ID bigint(20) NOT NULL auto_increment,
cat_name varchar(55) NOT NULL default '',
@ -13,7 +22,7 @@ $wp_queries="CREATE TABLE $wpdb->categories (
links_private tinyint(1) NOT NULL default '0',
PRIMARY KEY (cat_ID),
KEY category_nicename (category_nicename)
);
) $charset_collate;
CREATE TABLE $wpdb->comments (
comment_ID bigint(20) unsigned NOT NULL auto_increment,
comment_post_ID int(11) NOT NULL default '0',
@ -33,14 +42,14 @@ CREATE TABLE $wpdb->comments (
PRIMARY KEY (comment_ID),
KEY comment_approved (comment_approved),
KEY comment_post_ID (comment_post_ID)
);
) $charset_collate;
CREATE TABLE $wpdb->link2cat (
rel_id bigint(20) NOT NULL auto_increment,
link_id bigint(20) NOT NULL default '0',
category_id bigint(20) NOT NULL default '0',
PRIMARY KEY (rel_id),
KEY link_id (link_id,category_id)
);
) $charset_collate;
CREATE TABLE $wpdb->links (
link_id bigint(20) NOT NULL auto_increment,
link_url varchar(255) NOT NULL default '',
@ -59,7 +68,7 @@ CREATE TABLE $wpdb->links (
PRIMARY KEY (link_id),
KEY link_category (link_category),
KEY link_visible (link_visible)
);
) $charset_collate;
CREATE TABLE $wpdb->options (
option_id bigint(20) NOT NULL auto_increment,
blog_id int(11) NOT NULL default '0',
@ -74,14 +83,14 @@ CREATE TABLE $wpdb->options (
autoload enum('yes','no') NOT NULL default 'yes',
PRIMARY KEY (option_id,blog_id,option_name),
KEY option_name (option_name)
);
) $charset_collate;
CREATE TABLE $wpdb->post2cat (
rel_id bigint(20) NOT NULL auto_increment,
post_id bigint(20) NOT NULL default '0',
category_id bigint(20) NOT NULL default '0',
PRIMARY KEY (rel_id),
KEY post_id (post_id,category_id)
);
) $charset_collate;
CREATE TABLE $wpdb->postmeta (
meta_id bigint(20) NOT NULL auto_increment,
post_id bigint(20) NOT NULL default '0',
@ -90,7 +99,7 @@ CREATE TABLE $wpdb->postmeta (
PRIMARY KEY (meta_id),
KEY post_id (post_id),
KEY meta_key (meta_key)
);
) $charset_collate;
CREATE TABLE $wpdb->posts (
ID bigint(20) unsigned NOT NULL auto_increment,
post_author bigint(20) NOT NULL default '0',
@ -119,7 +128,7 @@ CREATE TABLE $wpdb->posts (
PRIMARY KEY (ID),
KEY post_name (post_name),
KEY type_status_date (post_type,post_status,post_date,ID)
);
) $charset_collate;
CREATE TABLE $wpdb->users (
ID bigint(20) unsigned NOT NULL auto_increment,
user_login varchar(60) NOT NULL default '',
@ -133,7 +142,7 @@ CREATE TABLE $wpdb->users (
display_name varchar(250) NOT NULL default '',
PRIMARY KEY (ID),
KEY user_login_key (user_login)
);
) $charset_collate;
CREATE TABLE $wpdb->usermeta (
umeta_id bigint(20) NOT NULL auto_increment,
user_id bigint(20) NOT NULL default '0',
@ -142,7 +151,7 @@ CREATE TABLE $wpdb->usermeta (
PRIMARY KEY (umeta_id),
KEY user_id (user_id),
KEY meta_key (meta_key)
);";
) $charset_collate;";
function populate_options() {
global $wpdb, $wp_db_version;

View File

@ -4,6 +4,8 @@ define('DB_NAME', 'wordpress'); // The name of the database
define('DB_USER', 'username'); // Your MySQL username
define('DB_PASSWORD', 'password'); // ...and password
define('DB_HOST', 'localhost'); // 99% chance you won't need to change this value
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', 'utf8_general_ci');
// You can have multiple installations in one database if you give each a unique prefix
$table_prefix = 'wp_'; // Only numbers, letters, and underscores please!
@ -18,4 +20,4 @@ define ('WPLANG', '');
define('ABSPATH', dirname(__FILE__).'/');
require_once(ABSPATH.'wp-settings.php');
?>
?>

View File

@ -3,6 +3,6 @@
// This holds the version number in a separate file so we can bump it without cluttering the SVN
$wp_version = '2.2-bleeding';
$wp_db_version = 4859;
$wp_db_version = 4860;
?>

View File

@ -35,6 +35,9 @@ class wpdb {
var $optiongroup_options;
var $postmeta;
var $charset;
var $collate;
/**
* Connects to the database server and selects a database
* @param string $dbuser
@ -49,6 +52,12 @@ class wpdb {
function __construct($dbuser, $dbpassword, $dbname, $dbhost) {
register_shutdown_function(array(&$this, "__destruct"));
if ( defined('DB_CHARSET') )
$this->charset = DB_CHARSET;
if ( defined('DB_COLLATE') )
$this->collate = DB_COLLATE;
$this->dbh = @mysql_connect($dbhost, $dbuser, $dbpassword);
if (!$this->dbh) {
$this->bail("
@ -63,6 +72,9 @@ class wpdb {
");
}
if ( !empty($this->charset) && version_compare(mysql_get_server_info(), '4.1.0', '>=') )
$this->query("SET NAMES '$this->charset'");
$this->select($dbname);
}