Page 1 of 1

Problem with special chars extracting from database in php

Posted: Fri Feb 16, 2007 3:04 pm
by Darla
Hello

I have a database table where I have some values containing the special letters æ, ø or å.

Upon fetching them it seems Ø turns into a simple "?":

Code: Select all

$sql = "SELECT description, count(description) AS count FROM userdata WHERE datetime like '".$datetime."%' GROUP BY description ORDER BY count DESC LIMIT 1";
$result = mysql_query($sql);
$descres= mysql_fetch_array($result);

echo "description:" . $descres['description'] ;

Here is an example of output - the value should have been "SØ" like it is in the database:
"description:S�"

Great if someone have some idea why.

Darla

Posted: Fri Feb 16, 2007 5:21 pm
by andym01480
Could it be the collation of the database set so those values aren't stored as you want?
http://dev.mysql.com/tech-resources/art ... icode.html

Plus also the character set of your page? Which for this one is

Code: Select all

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

Posted: Sat Feb 17, 2007 2:38 am
by ddragas
set collation of table utf-8, and before inserting values into database use utf8_encode() function , and when retrieving values from database use utf-8_decode() function