MarkDHamill
Joined: 30 Jan 2010
Posts: 8
Posted: 2010-05-31 16:17
Back to top
Reply with quote
|
Where would I add the following statement?
Code: |
mysql_set_charset('utf8'); |
I've had to add this statement to other scripts I have written against my database because it appears my MySQL installation will not output UTF-8 by default. The result is funny characters on output when I am showing certain words in French.
I realize that the setup program can create headers that can specify the page is in UTF-8 but it alone will not solve my problem. I also have to tell MySQL to send data in UTF-8.
|
doug
Joined: 10 Feb 2003
Posts: 1013
Location: Denver, Colorado (USA)
Posted: 2010-06-02 12:05
Back to top
Reply with quote
|
See the article referenced at
http://opensource.platon.sk/forum/projects/viewtopic.php?t=1152728
|
MarkDHamill
Joined: 30 Jan 2010
Posts: 8
Posted: 2010-06-02 13:28
Back to top
Reply with quote
|
However, I don't think this is going to help because as best I can tell the data is encoded correctly in the database.
Collation information:
Code: |
phpBB3 utf8_general_ci |
Varchar columns have the following collation:
In addition using a tool like phpMyAdmin I can edit data successfully in UTF-8.
It's something about MySQL not outputting data in UTF-8 by default. Since I am using shared hosting I don't think I can edit the my.cnf file. So I need to issue a statement to set the output type, which works. So I think if I add a statement like this at the appropriate place in the phpMyEdit code my problem will mysteriously disappear, as it has in the past.
Code: |
mysql_set_charset('utf8'); |
|
doug
Joined: 10 Feb 2003
Posts: 1013
Location: Denver, Colorado (USA)
Posted: 2010-06-02 16:16
Back to top
Reply with quote
|
The correct META tags must appear in your HTML code, for example:
Code: |
<meta http-equiv="charset" content="UTF-8">
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> |
|
MarkDHamill
Joined: 30 Jan 2010
Posts: 8
Posted: 2010-06-03 22:48
Back to top
Reply with quote
|
I'm sorry, I added both those lines to my HTML and they did not solve the problem.
|
doug
Joined: 10 Feb 2003
Posts: 1013
Location: Denver, Colorado (USA)
Posted: 2010-06-03 22:56
Back to top
Reply with quote
|
If the data was *always* UTF8 (never in Latin1 or any other format), the appropriate META tags are in place, and the appropriate queries are issued after the db connection, then it should be working. Are you sure your PHP version supports the function referenced above?
http://www.oreillynet.com/onlamp/blog/2006/01/turning_mysql_data_in_latin1_t.html
Dump your web browser cache, close the browser, and re-open (since sometimes they misbehave and display cached pages even on reload).
|
MarkDHamill
Joined: 30 Jan 2010
Posts: 8
Posted: 2010-06-03 23:30
Back to top
Reply with quote
|
I tried it in another browser and the same problem persists.
You can see it here. As you can see from the source code, the meta tags are applied.
Thanks for your help.
|
MarkDHamill
Joined: 30 Jan 2010
Posts: 8
Posted: 2010-06-05 23:34
Back to top
Reply with quote
|
I seem to have fixed the problem by modifying the function sql_connect in phpMyEdit.class.php as follows:
Code: |
function sql_connect() /* {{{ */
{
$this->dbh = @ini_get('allow_persistent')
? @mysql_pconnect($this->hn, $this->un, $this->pw)
: @mysql_connect($this->hn, $this->un, $this->pw);
mysql_set_charset('utf8');
} /* }}} */ |
|
jdevlieghere
Joined: 30 Apr 2012
Posts: 1
Posted: 2012-04-30 11:06
Back to top
Reply with quote
|
This last suggestion did the trick for me too - thx!
By the way, the official PHP documentation states:
"This (= mysql_set_charset) is the preferred way to change the charset. Using mysql_query() to execute SET NAMES .. is not recommended."
http://php.net/manual/en/function.mysql-set-charset.php
|
gutenzwerg
Joined: 29 Mar 2012
Posts: 4
Posted: 2013-05-11 17:02
Back to top
Reply with quote
|
This last suggestion did the trick for me too - thx!
gutenzwerg
|
Post new topic
Reply to topic
|