WordPress.org

Forums

Create table with utf8 charset (1 post)

  1. ronnyrook
    Member
    Posted 2 years ago #

    Hello WordPress users,

    I've just created a new table with my plugin trough this code:

    global $diensten_db_version;
    $diensten_db_version = "1.0";
    
    function diensten_install() {
        global $wpdb;
        global $diensten_db_version;
    
        $table_name = $wpdb->prefix . "diensten";
    
        $sql = "CREATE TABLE $table_name (
            id int(11) NOT NULL AUTO_INCREMENT,
            titel varchar(155) NOT NULL,
            price varchar(2) NOT NULL,
            category varchar(155) NOT NULL,
            PRIMARY KEY  (id),
            UNIQUE KEY id (id)
        ) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
    
        require_once( ABSPATH . 'wp-admin/includes/upgrade.php');
        dbDelta( $sql );
    
        add_option( "diensten_db_version", $diensten_db_version);
    }
        register_activation_hook( __FILE__, 'diensten_install' );

    But the charset is set the latin-1.
    When I copy this code directly in phpMyAdmin utf8 charset will be taken.

    Why wordpress is not taking this charset?

    Thanks for the help!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.