Jump to content

Problem with special chars extracting from database in php


Darla

Recommended Posts

Hello

 

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

 

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

 

 

$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

Link to comment
Share on other sites

Ah, dbs (like mysql) and their tables have a collation set to them, basically it's what the kind of characters it can accept. If you've got access to PHPMyAdmin to your database, you can use that to set the collation to something like latin1_swedish_ci or something of the like.

 

If you don't, you can run something like this SQL against your db

 

ALTER TABLE yourtable DEFAULT COLLATE latin1;

 

At least, that should be it. I'm not 100% sure latin1 is the right collation. Either that or something else characterset related. Probably in the HTML's metatag?

 

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

Link to comment
Share on other sites

Hello

 

Thanks for tips, but it seems id did not help. Regarding the ALTER TABLE yourtable DEFAULT COLLATE latin1; - do you think this will help? It is stored correct in the database you see, with SØ. It is when I fetch it in php it turns out wrong. Could there be something with

mysql_fetch_array($result); or something? I have tried utf-8 decoding it but it seems it is not utf-8 code.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.