Title: wpdb::init_charset
Published: April 25, 2014
Last modified: February 24, 2026

---

# wpdb::init_charset()

## In this article

 * [Source](https://developer.wordpress.org/reference/classes/wpdb/init_charset/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wpdb/init_charset/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wpdb/init_charset/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wpdb/init_charset/?output_format=md#wp--skip-link--target)

Sets $this->charset and $this->collate.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wpdb/init_charset/?output_format=md#source)󠁿

    ```php
    public function init_charset() {
    	$charset = '';
    	$collate = '';

    	if ( function_exists( 'is_multisite' ) && is_multisite() ) {
    		$charset = 'utf8';
    		if ( defined( 'DB_COLLATE' ) && DB_COLLATE ) {
    			$collate = DB_COLLATE;
    		} else {
    			$collate = 'utf8_general_ci';
    		}
    	} elseif ( defined( 'DB_COLLATE' ) ) {
    		$collate = DB_COLLATE;
    	}

    	if ( defined( 'DB_CHARSET' ) ) {
    		$charset = DB_CHARSET;
    	}

    	$charset_collate = $this->determine_charset( $charset, $collate );

    	$this->charset = $charset_collate['charset'];
    	$this->collate = $charset_collate['collate'];
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wpdb.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/class-wpdb.php#L840)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/class-wpdb.php#L840-L863)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wpdb/init_charset/?output_format=md#related)󠁿

| Uses | Description | 
| [wpdb::determine_charset()](https://developer.wordpress.org/reference/classes/wpdb/determine_charset/)`wp-includes/class-wpdb.php` |

Determines the best charset and collation to use given a charset and collation.

  | 
| [is_multisite()](https://developer.wordpress.org/reference/functions/is_multisite/)`wp-includes/load.php` |

Determines whether Multisite is enabled.

  |

| Used by | Description | 
| [wpdb::db_connect()](https://developer.wordpress.org/reference/classes/wpdb/db_connect/)`wp-includes/class-wpdb.php` |

Connects to and selects database.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wpdb/init_charset/?output_format=md#changelog)󠁿

| Version | Description | 
| [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwpdb%2Finit_charset%2F)
before being able to contribute a note or feedback.