Problem with special chars extracting from database in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Darla
Forum Newbie
Posts: 16
Joined: Mon Feb 12, 2007 8:27 am

Problem with special chars extracting from database in php

Post 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
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Post 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">
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Post 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
Post Reply