wpdb::get_charset_collate PHP Method

get_charset_collate() public method

The database character collate.
Since: 3.5.0
public get_charset_collate ( ) : string
return string The database character collate.
    public function get_charset_collate()
    {
        $charset_collate = '';
        if (!empty($this->charset)) {
            $charset_collate = "DEFAULT CHARACTER SET {$this->charset}";
        }
        if (!empty($this->collate)) {
            $charset_collate .= " COLLATE {$this->collate}";
        }
        return $charset_collate;
    }

Usage Example

コード例 #1
0
 /**
  * Creates the database table. It is also responsible for recreating the table if it is not up-to-date.
  **/
 public function create_table()
 {
     $current_version = get_option('wpfepp_db_table_version');
     if ($current_version && $current_version == $this->db_version && $this->db->get_var("SHOW TABLES LIKE '{$this->table_name}'") == $this->table_name) {
         return;
     }
     $charset_collate = $this->db->get_charset_collate();
     $sql = "\r\n\t\t\tCREATE TABLE {$this->table_name} (\r\n\t\t\t\tid MEDIUMINT(9) NOT NULL AUTO_INCREMENT,\r\n\t\t\t\tname TINYTEXT NOT NULL,\r\n\t\t\t\tpost_type TINYTEXT NOT NULL,\r\n\t\t\t\tdescription TEXT NULL,\r\n\t\t\t\tfields LONGTEXT NULL,\r\n\t\t\t\tsettings LONGTEXT NULL,\r\n\t\t\t\temails LONGTEXT NULL,\r\n\t\t\t\tUNIQUE KEY id (id)\r\n\t\t\t) {$charset_collate};\r\n\t\t";
     require_once ABSPATH . 'wp-admin/includes/upgrade.php';
     dbDelta($sql);
     update_option('wpfepp_db_table_version', $this->db_version);
 }