WordPress.org

Make WordPress Core

Ticket #3517: charset.diff

File charset.diff, 5.4 KB (added by ryan, 14 years ago)

Support for declaring charset for new installs under mysql >= 4.1

  • wp-includes/wp-db.php

     
    3535        var $optiongroup_options;
    3636        var $postmeta;
    3737
     38        var $charset;
     39        var $collate;
     40
    3841        /**
    3942         * Connects to the database server and selects a database
    4043         * @param string $dbuser
     
    4952        function __construct($dbuser, $dbpassword, $dbname, $dbhost) {
    5053                register_shutdown_function(array(&$this, "__destruct"));
    5154
     55                if ( defined('DB_CHARSET') )
     56                        $this->charset = DB_CHARSET;
     57
     58                if ( defined('DB_COLLATE') )
     59                        $this->collate = DB_COLLATE;
     60
    5261                $this->dbh = @mysql_connect($dbhost, $dbuser, $dbpassword);
    5362                if (!$this->dbh) {
    5463                        $this->bail("
     
    6372");
    6473                }
    6574
     75                if ( !empty($this->charset) && version_compare(mysql_get_server_info(), '4.1.0', '>=') )
     76                        $this->query("SET NAMES '$this->charset'");
     77
    6678                $this->select($dbname);
    6779        }
    6880
  • wp-includes/version.php

     
    33// This holds the version number in a separate file so we can bump it without cluttering the SVN
    44
    55$wp_version = '2.2-bleeding';
    6 $wp_db_version = 4772;
     6$wp_db_version = 4845;
    77
    88?>
  • wp-config-sample.php

     
    44define('DB_USER', 'username');     // Your MySQL username
    55define('DB_PASSWORD', 'password'); // ...and password
    66define('DB_HOST', 'localhost');    // 99% chance you won't need to change this value
     7define('DB_CHARSET', 'utf8');
     8define('DB_COLLATE', 'utf8_general_ci');
    79
    810// You can have multiple installations in one database if you give each a unique prefix
    911$table_prefix  = 'wp_';   // Only numbers, letters, and underscores please!
     
    1820
    1921define('ABSPATH', dirname(__FILE__).'/');
    2022require_once(ABSPATH.'wp-settings.php');
    21 ?>
    22  No newline at end of file
     23?>
  • wp-admin/upgrade-schema.php

     
    11<?php
    22// Here we keep the DB structure and option values
    33
     4$charset_collate = '';
     5       
     6if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') ) {
     7        if ( ! empty($wpdb->charset) )
     8                $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
     9        if ( ! empty($wpdb->collate) )
     10                $charset_collate .= " COLLATE $wpdb->collate"; 
     11}
     12
    413$wp_queries="CREATE TABLE $wpdb->categories (
    514  cat_ID bigint(20) NOT NULL auto_increment,
    615  cat_name varchar(55) NOT NULL default '',
     
    1322  links_private tinyint(1) NOT NULL default '0',
    1423  PRIMARY KEY  (cat_ID),
    1524  KEY category_nicename (category_nicename)
    16 );
     25) $charset_collate;
    1726CREATE TABLE $wpdb->comments (
    1827  comment_ID bigint(20) unsigned NOT NULL auto_increment,
    1928  comment_post_ID int(11) NOT NULL default '0',
     
    3342  PRIMARY KEY  (comment_ID),
    3443  KEY comment_approved (comment_approved),
    3544  KEY comment_post_ID (comment_post_ID)
    36 );
     45) $charset_collate;
    3746CREATE TABLE $wpdb->link2cat (
    3847  rel_id bigint(20) NOT NULL auto_increment,
    3948  link_id bigint(20) NOT NULL default '0',
    4049  category_id bigint(20) NOT NULL default '0',
    4150  PRIMARY KEY  (rel_id),
    4251  KEY link_id (link_id,category_id)
    43 );
     52) $charset_collate;
    4453CREATE TABLE $wpdb->links (
    4554  link_id bigint(20) NOT NULL auto_increment,
    4655  link_url varchar(255) NOT NULL default '',
     
    5968  PRIMARY KEY  (link_id),
    6069  KEY link_category (link_category),
    6170  KEY link_visible (link_visible)
    62 );
     71) $charset_collate;
    6372CREATE TABLE $wpdb->options (
    6473  option_id bigint(20) NOT NULL auto_increment,
    6574  blog_id int(11) NOT NULL default '0',
     
    7483  autoload enum('yes','no') NOT NULL default 'yes',
    7584  PRIMARY KEY  (option_id,blog_id,option_name),
    7685  KEY option_name (option_name)
    77 );
     86) $charset_collate;
    7887CREATE TABLE $wpdb->post2cat (
    7988  rel_id bigint(20) NOT NULL auto_increment,
    8089  post_id bigint(20) NOT NULL default '0',
    8190  category_id bigint(20) NOT NULL default '0',
    8291  PRIMARY KEY  (rel_id),
    8392  KEY post_id (post_id,category_id)
    84 );
     93) $charset_collate;
    8594CREATE TABLE $wpdb->postmeta (
    8695  meta_id bigint(20) NOT NULL auto_increment,
    8796  post_id bigint(20) NOT NULL default '0',
     
    9099  PRIMARY KEY  (meta_id),
    91100  KEY post_id (post_id),
    92101  KEY meta_key (meta_key)
    93 );
     102) $charset_collate;
    94103CREATE TABLE $wpdb->posts (
    95104  ID bigint(20) unsigned NOT NULL auto_increment,
    96105  post_author bigint(20) NOT NULL default '0',
     
    119128  PRIMARY KEY  (ID),
    120129  KEY post_name (post_name),
    121130  KEY type_status_date (post_type,post_status,post_date,ID)
    122 );
     131) $charset_collate;
    123132CREATE TABLE $wpdb->users (
    124133  ID bigint(20) unsigned NOT NULL auto_increment,
    125134  user_login varchar(60) NOT NULL default '',
     
    133142  display_name varchar(250) NOT NULL default '',
    134143  PRIMARY KEY  (ID),
    135144  KEY user_login_key (user_login)
    136 );
     145) $charset_collate;
    137146CREATE TABLE $wpdb->usermeta (
    138147  umeta_id bigint(20) NOT NULL auto_increment,
    139148  user_id bigint(20) NOT NULL default '0',
     
    142151  PRIMARY KEY  (umeta_id),
    143152  KEY user_id (user_id),
    144153  KEY meta_key (meta_key)
    145 );";
     154) $charset_collate;";
    146155
    147156function populate_options() {
    148157        global $wpdb, $wp_db_version;