FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


UTF-8 from MySQL to PHP





Peterssidan
I have PHP and Mysql on my computer. I'm using utf-8 but I have some problems. When I receive utf-8 encoded strings from mysql (using SELECT...) some characters like is showed like a question marks on the page but it will work if I write it on the page directly.

I googled and found
Code:
mysql_query("SET NAMES 'utf8'");
That code makes it shows like it should. Is this the way to go or should I set some option elsewhere to not have to set this on every page?

Another question I have is about utf-8 CHAR as primary key. I read somewhere that if you use CHAR in utf-8 it will always take up much more than it have to because it doesn't know how much space it will take. I really want to use CHAR and not numerical values as primary key on some tables. The good thing is that I don't need to use utf-8 characters in these keys (only ASCII-characters) So should I then use some other collation on these rows? witch?
sonam
Can you provide us with link to your site. Normaly, if you are use utf-8 in your mysql table it is necessary to have meta tag utf-8
Code:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

on both pages: in form (from where you insert data) and on page where you display result.

For second question I think it is possible to define different charset for each column in phpmyadmin in cpanel or DA.

Sonam
phucngo
sonam wrote:
Can you provide us with link to your site. Normaly, if you are use utf-8 in your mysql table it is necessary to have meta tag utf-8
Code:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

on both pages: in form (from where you insert data) and on page where you display result.

For second question I think it is possible to define different charset for each column in phpmyadmin in cpanel or DA.

Sonam


Another way is as below:
Code:
mb_internal_encoding( "UTF-8" );
mb_regex_encoding( "UTF-8" );
header( "Content-type: text/html; charset=UTF-8" );

Those codes should be included at the beginning of each PHP file and make sure that PHP files are saved in UTF-8 encoding too.
Related topics
Switching to UTF-8
Does the php support utf8?
utf-8 cMS
MySQL and PHP problem in the future
MySQL, PHP and APACHE
PHP&Ajax Trke karakter sorunu
Is mySQL/php in safe mode on Frihosting?
Converter banco de dados para UTF-8
PhpMyAdmin and UTF-8
cannot add data to mysql from PHP form
Problem with NAVICAT 8 for mysql
Bases de datos UTF-8
PHP utf-8 to Java Applet
search, a bit contextual in php
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.