Jump to content

MySQL Charset Issue


suttercain

Recommended Posts

Hi Everyone,

 

I am doing a project and some of the database information is being displayed in the borwser as a tilted box with a question mark inside.

 

Does anyone know what I should set my charset to be to avoid this? The website will be for us residents.

 

Thanks

 

SC

Link to comment
https://forums.phpfreaks.com/topic/62050-mysql-charset-issue/
Share on other sites

Log into MySQL and type the command \s, this will give you the status information and the character set configurations:

Server characterset:    latin1

Db    characterset:    latin1

Client characterset:    latin1

Conn.  characterset:    latin1

What do you have for these? What version of MySQL?

What character set is your program using, either in your headers, or meta tag?

 

Link to comment
https://forums.phpfreaks.com/topic/62050-mysql-charset-issue/#findComment-308938
Share on other sites

The data coming from MySQL will be UTF-8. Changing charset in your meta tag to "utf-8" should fix the issue.

 

In versions 4.1 (I think, definitely 4.2) and up you have to do the following.

 

When you connect to your database, you have to tell it what charset you want. Otherwise, you will get garbage.

 

$db = mysql_connect('localhost','user','pass' ) or die ( Could not connect: ' . mysql_error() );
mysql_select_db( 'dbname' ) or die;

if ( !mysql_query("SET CHARACTER SET utf8", $db ) ) {
        echo "problem setting character<br>";
}

if ( !mysql_query("SET NAMES 'utf8'", $db ) ) {
        echo "problem setting name<Br>";
}

 

Noticy in effigy's post there's a client portion.  You need to have this set (check you my.cnf) for it to work right, AFAIK, and the charset in the above queries need to match the client collation & charset.  FYI, if you're going to deal w/ multibyte characers, leave it in Unicode.  You will kill yourself messing w/ the others. ;)

Link to comment
https://forums.phpfreaks.com/topic/62050-mysql-charset-issue/#findComment-309022
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.