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
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
Share on other sites

Hi Effigy

 

Meta Doc <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

 

Collation latin1_swedish_ci

 

MySQL charset:  UTF-8 Unicode (utf8)

 

MySQL connection collation: UTF-8 Unicode_ci

 

MySQL 5

 

 

Thanks

Link to comment
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.