Jump to content

Recommended Posts

Hello,

 

I see funny characters in my database when im trying to save data to the database with other characters apart english. And i cant retrieve them later, neither to see the inserted text via phpMyAdmin. The web page that holds the php code has as charset utf8. My database is mysql 5.x and the all fields and tables have collation utf8_general_ci

 

Is there any idea or something that i can do in order to resolve it? At least to save them in the database with a readable morph. The language im going to save is Greek. thus I use utf8

 

Thank you in advance

Link to comment
https://forums.phpfreaks.com/topic/78981-solved-utf8-storing-values/
Share on other sites

As long as you declare utf-8 as the encoding in your html document, and all the mysql stuff is utf-8, AND use

 

<?php
//connect to your database here (the mysql_connect is stored in $connection in this example)
mysql_query('SET CHARACTER SET utf8', $connection);
mysql_query('SET NAMES utf8', $connection);
//your query here
?>

 

to retrieve data from the database, you should be a-okay.

Thanks for your reply,

 

I have done it and works, also I found that it works just with this line mysql_query('SET NAMES utf8');

 

Now I have an other problem that its ridiculous. I use joomla and ajax_shoutbox chat. you write something and everybody sees it on the site's front page...

 

before i use those 2 lines of the solution, I was writing greek but nobody else could see them, because it was saving funny characters is the DB.

 

Now, every body can see my message in greek in the front page.

 

The problem: whoever is on-line, including me, is not able to see what the message is, the characters are questionmarks. But whenever the page is refreshed everything is shown fine.

 

Im wondering how these 2 php lines

mysql_query('SET CHARACTER SET utf8', $connection);

mysql_query('SET NAMES utf8', $connection);

 

affects the overall script, I think Javascript. Any ideas?

 

If this issue is shorted out, A lot of scripts can get modified to utf8. For the greek versioni will put a credit to this forum.

 

Please ask me for any part of the code.

 

Thanks in advance for any help. If i have news I will post them here

<?
function jal_special_chars ($s) {
  $s = htmlspecialchars( $s, ENT_COMPAT , shoutbox_encoding );
  if ( strtolower ( shoutbox_encoding ) != 'utf-8' )
       $s = utf8_decode ( $s );
  return str_replace("---","−-−",$s);
}
?>

 

I found it interesting and i post it in case somebody likes to give a hand

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.