snk Posted November 26, 2007 Share Posted November 26, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/78981-solved-utf8-storing-values/ Share on other sites More sharing options...
thebadbad Posted November 26, 2007 Share Posted November 26, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/78981-solved-utf8-storing-values/#findComment-399784 Share on other sites More sharing options...
snk Posted November 26, 2007 Author Share Posted November 26, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/78981-solved-utf8-storing-values/#findComment-399841 Share on other sites More sharing options...
snk Posted November 26, 2007 Author Share Posted November 26, 2007 <? 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 Quote Link to comment https://forums.phpfreaks.com/topic/78981-solved-utf8-storing-values/#findComment-399850 Share on other sites More sharing options...
thebadbad Posted November 27, 2007 Share Posted November 27, 2007 Please show all your code that's relevant to the shoutbox. Quote Link to comment https://forums.phpfreaks.com/topic/78981-solved-utf8-storing-values/#findComment-400205 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.