Page 1 of 1
specials characters not retrieved using uft-8
Posted:
08. October 2007 17:58
by blueboy
I used Appserv apache-mysql-php distribution without any problem.
Then I shift to XAMPP, and I have got a problem displaying data that contain á,é,í,ó,ú or ñ from mysql, by using php, so that when I retrieve them from mysql via php I get a kind of ? sign.
My data are stored in mysql and they are setted to utf-8 an so in <meta content> of the *.php doc.
When I write á,é,í,ó,ú or ñ in HTML I get them right, but when I retrieve them from mysql via php I get a kind of ? sign and at least two characters are lost.
Any idea?
Otherwise I have to move back to Appserv...and it has less integrated functions![/list]
Posted:
08. October 2007 18:54
by Wiedmann
My data are stored in mysql and they are setted to utf-8
What did you mean with this?
I have got a problem displaying data that contain á,é,í,ó,ú or ñ from mysql, by using php, so that when I retrieve them from mysql via php I get a kind of ? sign.
You have told MySQL, that you want the results in UTF-8?
Posted:
09. October 2007 09:00
by blueboy
Sorry, for not to be clear, I describe my situation again:
1.- I have data stored in mysql in uft-8 format.
2.- Then I use php to retrieve them .
3.- In my pages the charset is set to uft-8.
4.-An finally, in my pages, when I show data stored in mysql that contain á,é,í,ó,ú or ñ , by using php, I get a kind of ? sign.( Let's say in mysql is stored "camión" and in firefox or explorer I get "cami?n".
5.- And, by the way, if I have in html "camión" firefox or explorer show "camión" without any problem.
6.- And all this did not happen using the AppServ distribution of apache-mysql-php, however I'd like to use XAMPP distribution because it has many more features.
Posted:
09. October 2007 10:02
by lyntuan
.
Posted:
09. October 2007 10:26
by blueboy
Thaks a lot...I'll try it!!!
Posted:
09. October 2007 15:13
by sari42
..and to make Geckos feel happy:
header("Content-Type: text/html; charset=utf-8");
Problem resolved...thanks to everybody...
Posted:
09. October 2007 23:17
by blueboy
Here is the solution...
Open you prefered editor...
and open C:\xampp\mysql\bin\my.cnf
And write this (just the bold sentences the other stuff is already written):
my.cnf :
.../
[client]
# password = your_password
port = 3306
socket = mysql
default-character-set = utf8
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
basedir="C:/xampp/mysql"
tmpdir="C:/xampp/tmp"
datadir="C:/xampp/mysql/data"
# The default character set that will be used when a new schema or table is
# created and no character set is defined
default-character-set = utf8
character-set-server = utf8
collation-server = utf8_general_ci
init_connect = 'SET collation_connection = utf8_general_ci'
init_connect = 'SET NAMES utf8'
.../
Then you have to shut down and restart mysql from c:\xampp directory .bat files or to uninstall it as service and then reinstall from c:\xampp\mysql .bat files ( so that you remove c:\windows\my.ini and put the new one).
And if you have the data stored in mysql as utf-8 and in your header also charsert=utf-8..you can use any kind of character at your website without any problem.
Posted:
10. October 2007 00:46
by Wiedmann
- Code: Select all
init_connect = 'SET collation_connection = utf8_general_ci'
init_connect = 'SET NAMES utf8'
This does not work with all MySQL user accounts....
and in your header also charsert=utf-8..
If you provide your HTML pages in UTF-8, you must say to MySQL, that your queries are in UTF-8 and you want the results in UTF-8. (regardless in which charset the data is stored in MySQL). This is done with this query:
- Code: Select all
SET NAMES 'UTF8'
(and with this query in your code, this works with all user accounts)
In "my.cnf", that's all you need (if you want UTF-8 as default for new databases/tables):
- Code: Select all
[client]
default-character-set=utf8
[mysqld]
default-character-set=utf8
But you can also make UTF-8 databases with the old default "latin1". Just use the CHARSET option in the "CREATE DATABASE" statement.
BTW: PHP don't use the "my.cnf".