mysql encoding_mysql_client_encoding

用户评论:

[#1]

devos at montp dot inserm dot fr [2007-08-23 03:30:12]

I use mysql 3.23 and none of the above worked for me. Looking at http://dev.mysql.com/tech-resources/articles/4.1/unicode.html as advised by romain at dardour dot com, I tried to include the following header in my php scripts, and all the funy characters disapeared. Hope it will help.

(my mysql character was latin1)

[#2]

php at quarkus dot de [2007-07-25 06:23:47]

Please note that even if you set the charset by issuing the two mentioned SQL statements (set names, set character set) mysql_client_encoding still deliveres the old result.

Default for me is latin1. After switching to UTF8 mysql_client_encoding still returns latin1. The charset switched to UTF8 successfully, though.

[#3]

roy dot the dot geek+php at gmail dot com [2007-01-23 05:37:17]

f you think "set names utf8" for each connection is too trouble, you can modify my.cnf of MySQL to solve the problem forever. In my.cnf, add the line "default-character-set=utf8" in both [mysqld] and [client] sections:

[client]

default-character-set=utf8

[mysqld]

default-character-set=utf8

The MySQL will use utf8 after you restart it.

[#4]

Pedro Pereira [2006-09-09 07:30:46]

All I had to do to save utf8 data with php mysql_query() was to go to the php.ini and put default_charset = "utf-8". Without this I had the same problems some of you have. Plus, all my mysql charsets vars are in 'utf8'. (Changed them with Mysql Admin Tool)

Didnt use any mysql SET **** command at all.

Mysql 4.1.20

PHP 4.4.4

Win XP

Hope this help some of you.

[#5]

alamakota at mises dot pl [2006-07-26 07:13:51]

There's no 'character_set' variable available in MySQL. You can check it yourself in MySQL online documentation or by running MySQL query "SHOW VARIABLES LIKE 'character_set%';".

This must be an error in PHP manual, unless I'm missing something.

[#6]

[2006-07-21 05:46:29]

A very easy way to always get results in UTF-8 is to make a common function to connect to DB and in that function set character set to utf-8.

function OpenConn() {

global $link;

$link = mysql_connect ("localhost", "username", "password")

or die(sendError('Could not connect to DB'));

mysql_select_db ("dbName");

//

// Set character set to UTF-8

//

mysql_query("SET CHARACTER SET 'utf8'", $link);

}

[#7]

romain at dardour dot com [2006-05-15 08:56:04]

I couldn't get any luck with all the stuff mentioned below, and despite having an unicode DB, and setting all my field to utf8_general_ci...

After looking around, I found that this page: http://dev.mysql.com/tech-resources/articles/4.1/unicode.html was adding the fields with an extra info before each value:

mysql_query("INSERT INTO table SET field = _utf8'value'");?>

Mind the "_utf8" before the field value, and outside of the quotes.

This works for me wether in an Insert or an Update statement.

No need here for a <?php  mysql_query("SET NAMES utf8");?> before each query, or to change anything in the config files (that was important since I don't have access to these).

[#8]

zayfod at yahoo dot com [2006-04-21 04:57:23]

The right lines to put in /etc/my.cnf (or other MySQL options file) are:

[client]

init-command="SET NAMES utf8"

Unfortuantely the PHP mysql_connect() function does not use MySQL options files so this is not a sollution for changing the default connection character set for mysqlclient library v4.1+.

The only working sollution remains:

mysql_query("SET NAMES utf8", $conn);

(of course /ext/mysql/php_mysql.c can always be patched ;] )

[#9]

Wio at psitrax dot de [2006-03-16 09:24:23]

If you set the encoding in my.cnf like

[mysqld]

init_connect='SET NAMES utf8'

note that the content of init_connect  is not executed for users that have the SUPER privilege - ie root!

[#10]

vrbcik [2005-11-27 09:26:29]

I have had problems with encoding after export of tables (from hosting - via PhpMyAdmin) and import them to other machine (my notebook - via PhpMyAdmin too). In PhpMyAdmin the encoding of all data was shown correctly, not that good with the web pages (data pulled via php).

The first point is indication, that the data was imported correctly, but php script has got other character set than MySql is sending.

The script's character set is set in header: . MySql setting was latin1.

Then following code helped me:

mysql_query("SET CHARACTER SET 'latin2'",$conn);?>

[#11]

info at jantichy dot cz [2004-12-30 14:02:34]

Notice the difference between following two SQL statements:

SET NAMES 'charset_name'

SET CHARACTER SET charset_name

For more detail see

http://dev.mysql.com/doc/mysql/en/Charset-connection.html

[#12]

black at scene-si dot org [2004-10-20 04:04:54]

the above (as it seems to be vaguely indicated in the mysql manual) works only with mysql 4.1+

[#13]

stian at grytoyr dot net [2004-10-19 06:09:06]

If you experience weird problems, like some UTF-8 characters (the Unicode character č and a few others in my case) seemingly being changed to garbage by mysql_query, you may need to do something like this before your actual query:

mysql_query("SET NAMES 'utf8'",$conn);?>

Took me days to figure that one out...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值