Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

Need help with Warning: mysql_set_charset(): Error executing query on my wordpress website?

Warning: mysql_set_charset(): Error executing query in /home/titvar/proenablehealth.com/wp-includes/wp-db.php on line 782

Warning: Cannot modify header information - headers already sent by (output started at /home/titvar/proenablehealth.com/wp-includes/wp-db.php:782) in /home/titvar/proenablehealth.com/wp-includes/pluggable.php on line 1207

and this is the relevant code block

    if ( ! isset( $charset ) )
        $charset = $this->charset;
    if ( ! isset( $collate ) )
        $collate = $this->collate;
    if ( $this->has_cap( 'collation' ) && ! empty( $charset ) ) {
        if ( $this->use_mysqli ) {
            if ( function_exists( 'mysqli_set_charset' ) && $this->has_cap( 'set_charset' ) ) {
                mysqli_set_charset( $dbh, $charset );
            } else {
                $query = $this->prepare( 'SET NAMES %s', $charset );
                if ( ! empty( $collate ) )
                    $query .= $this->prepare( ' COLLATE %s', $collate );
                mysqli_query( $dbh, $query );
            }
        } else {
            if ( function_exists( 'mysql_set_charset' ) && $this->has_cap( 'set_charset' ) ) {
                mysql_set_charset( $charset, $dbh );
            } else {
                $query = $this->prepare( 'SET NAMES %s', $charset );
                if ( ! empty( $collate ) )
                    $query .= $this->prepare( ' COLLATE %s', $collate );
                mysql_query( $query, $dbh );
            }
        }
    }
}

2 Answers

in the wp-config.php file define('DB_CHARSET', 'utf8mb4');

how do i check if the database has same charset or not?

You'd have to access your database somehow. Depending on your hosting provider, you may have access through phpMyAdmin. Anyway, try changing the config file to utf8 and try again. If it doesn't work, check your database.

What's your charset set to in your database and what's it set to in your wp-config.php file?

They should both be the same, if they are not, try setting them both to utf8.