473,583 Members | 3,089 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Mysql database in UTF8, PHP shows latin1 (iso-8859-1)

I've converted a latin1 database I have to utf8. The process has been:

# mysqldump -u root -p --default-character-set=latin1 -c --insert-ignore
--skip-set-charset mydb mydb.sql

# iconv -f ISO-8859-1 -t UTF-8 mydb.sql mydb_utf8.sql

[then i replaced all CHARSET=latin1 to CHARSET=utf8 in the file, and
checked in the editor that non default characters as accents were viewed
correctly using UTF8 charset]

mysqlCREATE DATABASE mydb_utf8 CHARACTER SET utf8 COLLATE utf8_general_ci ;

# mysql -u root -p --default-character-set=utf8 mydb_utf8 < mydb_utf8.sql
I made a simple script in PHP to dump data from tables which had non
standard characters. But the resulting page is viewed correctly in
iso-8859-1 encoding and not in UTF-8.

At this moment i'm clueless were the problem lies.
..alex
Apr 4 '08 #1
39 5841
Am Fri, 04 Apr 2008 10:11:16 +0200 schrieb alex:
I made a simple script in PHP to dump data from tables which had non
standard characters. But the resulting page is viewed correctly in
iso-8859-1 encoding and not in UTF-8.
http://dev.mysql.com/doc/refman/5.0/...onnection.html

I guess using "set names utf8" should help.

Norbert
Apr 4 '08 #2
En/na Norbert Tretkowski ha escrit:
Am Fri, 04 Apr 2008 10:11:16 +0200 schrieb alex:
>I made a simple script in PHP to dump data from tables which had non
standard characters. But the resulting page is viewed correctly in
iso-8859-1 encoding and not in UTF-8.

http://dev.mysql.com/doc/refman/5.0/...onnection.html

I guess using "set names utf8" should help.
Yes, it helps, but why should i change my app?

I mean, if the database is set to utf8, the tables are utf8 too (and
just to check, i've also set under [client], [mysqld] and [server] the
value default_charact er_set=utf8), shouldn't php return me the string as
utf8?

Isn't this a bit bugged?
Apr 4 '08 #3
..oO(alex)
>En/na Norbert Tretkowski ha escrit:
>Am Fri, 04 Apr 2008 10:11:16 +0200 schrieb alex:
>>I made a simple script in PHP to dump data from tables which had non
standard characters. But the resulting page is viewed correctly in
iso-8859-1 encoding and not in UTF-8.

http://dev.mysql.com/doc/refman/5.0/...onnection.html

I guess using "set names utf8" should help.

Yes, it helps, but why should i change my app?

I mean, if the database is set to utf8, the tables are utf8 too (and
just to check, i've also set under [client], [mysqld] and [server] the
value default_charact er_set=utf8), shouldn't php return me the string as
utf8?

Isn't this a bit bugged?
Just storing the data as UTF-8 is not enough. You also have to set the
connection between MySQL and your script to UTF-8 and PHP has to send a
correct HTTP header back to the browser.

Micha
Apr 4 '08 #4
En/na Michael Fesser ha escrit:
>
Just storing the data as UTF-8 is not enough. You also have to set the
connection between MySQL and your script to UTF-8 and PHP has to send a
correct HTTP header back to the browser.
Ok, i know that i must send correct headers, but still having this
variables:

+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_c lient | utf8 |
| character_set_c onnection | utf8 |
| character_set_d atabase | utf8 |
| character_set_f ilesystem | binary |
| character_set_r esults | utf8 |
| character_set_s erver | utf8 |
| character_set_s ystem | utf8 |
| character_sets_ dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+

The output is ISO, and that is what freaks me out. :P
Apr 4 '08 #5
alex wrote:
En/na Michael Fesser ha escrit:
>>
Just storing the data as UTF-8 is not enough. You also have to set the
connection between MySQL and your script to UTF-8 and PHP has to send a
correct HTTP header back to the browser.

Ok, i know that i must send correct headers, but still having this
variables:

+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_c lient | utf8 |
| character_set_c onnection | utf8 |
| character_set_d atabase | utf8 |
| character_set_f ilesystem | binary |
| character_set_r esults | utf8 |
| character_set_s erver | utf8 |
| character_set_s ystem | utf8 |
| character_sets_ dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+

The output is ISO, and that is what freaks me out. :P
Check Micha's comment again:

"...and PHP has to send a correct HTTP header back to the browser."

The dataset connection and charset have nothing to do with the charset
sent in the page header. You can set the correct charset for the page
in your Apache server or in PHP.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Apr 4 '08 #6
it seems a php problem as when i execute "show variables" in an mysql
console i get:

character_set_c lient=utf8

but from php i get:

character_set_c lient=latin1
That is a problem I also had. the [mysql] section of my.cnf is for the
command-line client only. A [client] section may or may not be used for
PHP connections. I had to send a "SET NAMES utf8" upon connection to
really convince MySQL to use utf8 for the connection.

This really sucks, off course. It is plain stupid to have to set the
encoding used encoded in the encoding it has to set. It is like sending
a key INSIDE a safe which requires that key to open it.

Best regards,
--
Willem Bogaerts

Application smith
Kratz B.V.
http://www.kratz.nl/
Apr 4 '08 #7
..oO(Willem Bogaerts)
>it seems a php problem as when i execute "show variables" in an mysql
console i get:

character_set_ client=utf8

but from php i get:

character_set_ client=latin1

That is a problem I also had. the [mysql] section of my.cnf is for the
command-line client only. A [client] section may or may not be used for
PHP connections. I had to send a "SET NAMES utf8" upon connection to
really convince MySQL to use utf8 for the connection.
That's how it's supposed to be and was already mentioned multiple times.
How else should MySQL know what connection encoding the PHP client and
your scripts prefer?
>This really sucks, off course. It is plain stupid to have to set the
encoding used encoded in the encoding it has to set. It is like sending
a key INSIDE a safe which requires that key to open it.
You connect to the DB using the default encoding and then set it to
whatever you want it to be. There's nothing stupid about that.

Micha
Apr 4 '08 #8
I'm sorry, I should mention, I use:

Debian Etch stable
Apache2
PHP 5
Jun 27 '08 #9
Marc wrote:
alex schrieb:
>>
I made a simple script in PHP to dump data from tables which had non
standard characters. But the resulting page is viewed correctly in
iso-8859-1 encoding and not in UTF-8.

At this moment i'm clueless were the problem lies.

Hello,

well, first of all, I'm newbie with MYSQL & Co., I have read all answers
and followed the link reading them all carefully. I suppose I understand
the matter.

I have apparently the same problem as Alex has. But my connection is in
UTF-8 and I need ISO-8859-1.

The problem accrued as I've moved from my webspace to a vServer.

The old configuration shown by phpMyAdmin on MySQL 4.1.13 is:

character set client utf8
(Globaler Wert) latin1
character set connection utf8
(Globaler Wert) latin1
character set database latin1
character set results utf8
(Globaler Wert) latin1
character set server latin1
character set system utf8
collation connection utf8_general_ci
(Globaler Wert) latin1_swedish_ ci
collation database latin1_swedish_ ci
collation server latin1_swedish_ ci

The new configuration shown by phpMyAdmin on my new MySQL 5.0.32 is
exactly the same, the I set "SET NAMES latin1" via mysql-shell.

BUT:

Making "SHOW VARIABLES" at mysql-shell gives:

character_set_c lient latin1
character_set_c onnection latin1
character_set_d atabase latin1
character_set_f ilesystem binary
character set results latin1
character set server latin1
character set system utf8
collation connection latin1_swedish_ ci
collation database latin1_swedish_ ci
collation server latin1_swedish_ ci

asking for the values by PHP gives:

character_set_c lient utf8
character_set_c onnection utf8
character_set_d atabase latin1
character_set_f ilesystem binary
character_set_r esults utf8
character_set_s erver latin1
character_set_s ystem utf8
collation_conne ction utf8_general_ci
collation_datab ase latin1_swedish_ ci
collation_serve r latin1_swedish_ ci

I need the character_set_c lient and character_set_c onnection in latin1.

The HTTP header sends to the browser ISO-8859-15. That should stay so,
because about 2.000 html pages are coded in this. I don't care for the
DB contect, then I have it local in some programm. My only wish is to
establish a working-encoding-connection between the PHP and DB.

Can You please tell what exactly I have to do? Please, understand I
can't reprogramm the application, I even don't want to, because it
worked before. I'm quit sure it's not correct setted up.

Thanks a lot in advance!!!

Regards

Marc
Marc,

Look at the differences in your settings. Then look at the fact these
are MySQL settings, not PHP. And look at the questions you're asking -
about the character set in the connection and client.

These are all MySQL items - which should be a clue that you should be
asking in comp.databases. mysql, not here.
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Jun 27 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1439
by: cover | last post by:
Hi, Is there a site that anyone knows of, that shows creating a MySQL database from input through output is concerned? I'd LOVE to see a tutorial that included the interface for input, the usable MySQL database and then the query potential (including query interface). I'm new to MySQL and haven't been able to find much on the internal...
2
1665
by: donpro | last post by:
Hi, I have a varchar field in a MySQL database that contains a line of text like so: "This is a line if text" The double quotes are included in the database field. I cannot seem to display it on my HTML page, it always shows as blank.
0
1995
by: marcin | last post by:
I have problems with inserting Japanese chars into MySQL database. This operation results in two completetely different strings that I can see via phpMyAdmin: $word: SELECT word FROM table; INSERT $word INTO table; Both commands are executed direclty via PHP, phpMyAdmin shows the original word (inserted into table via phpMyAdmin) correctly...
12
2714
by: mistral | last post by:
phpMyAdmin 2.6.2 problem: can no connects to mySQL database: each time shown error #1045 - Access denied for user 'username'@'192.168.1.2' (using password: YES) Is seems, this is most common problem for mySOL and phpMyAdmin. Extremelly ugly and inconvenient program.
14
6084
by: mistral | last post by:
Need php script to create mySQL database programmatically; since hosting configuration may not allow create database from script, script also need eliminate/rewrite all restrictions in appropriate places in that hosting.
2
6314
by: Christoph Krammer | last post by:
Hello, I try to write a python application with wx that shows images from a MySQL database. I use the following code to connect and get data when some event was triggered: dbconn = MySQLdb.connect(host="localhost", user="...", passwd="...", db="images") dbcurs = dbconn.cursor() dbcurs.execute("""SELECT imgdata FROM images LIMIT 1""")
1
4800
myusernotyours
by: myusernotyours | last post by:
hi all, Am building an desktop app that needs to access a mysql database and am using netbeans 6 can someone direct me to a good tutorial that shows how this can be done?
0
1411
by: adajon92 | last post by:
I have a problem with mySQL database. To start off, I'm a super N00b and am trying to make a web page using PHP and MySQL for a class project. Currently the database and website are operational, using Apache2 and MySQL on a Ubuntu Server virtual machine. As of now I am trying to add information into the database using PHP. This is done using...
3
4379
by: Neil Domingo | last post by:
I have an online hosted website that uses mysql database. Now, what I am trying to do was to update my remote database. What I mean was, a different mysql database that is not online. I used php and mysql in my website and vb.net and mysql on the remote computer. I needed something of an update button on my vb.net application to...
0
7895
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7826
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8327
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7935
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6579
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5701
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3843
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2333
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.