solon Posted April 9, 2010 Share Posted April 9, 2010 Hey guys, I have a problem with searching greek characters in mysql using php script. In the database everything(in greek) is stored as html entities(i.e. α). Now, when i try to search from php like this $term = $_POST['search']; $fetch = mysql_query("SELECT `text`FROM pages INNER JOIN content ON (pages.page_id = content.page_id) WHERE frontpage = '1' and `pages`.`page_title_gr` like '%".$term."%' or `content`.`text` like '%".$term."%'"); the characters are displayed as normal greek letters (i.e. γεια) and i get no results. What might be the problem? Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/198111-php-mysql-problem-with-greek/ Share on other sites More sharing options...
Mchl Posted April 9, 2010 Share Posted April 9, 2010 If you stored greek character as html entities (one would wonder why), you have to search for html entitities. Quote Link to comment https://forums.phpfreaks.com/topic/198111-php-mysql-problem-with-greek/#findComment-1039641 Share on other sites More sharing options...
solon Posted April 11, 2010 Author Share Posted April 11, 2010 The greek characters are stored like that(htlml entities) from a php mysql script. Is there a way to do it differently? Solon Quote Link to comment https://forums.phpfreaks.com/topic/198111-php-mysql-problem-with-greek/#findComment-1040125 Share on other sites More sharing options...
Mchl Posted April 11, 2010 Share Posted April 11, 2010 Yeah. It's called UTF-8 Quote Link to comment https://forums.phpfreaks.com/topic/198111-php-mysql-problem-with-greek/#findComment-1040126 Share on other sites More sharing options...
solon Posted April 11, 2010 Author Share Posted April 11, 2010 i use utf-8 as the encoding but it still stores it like that. I have this in all my files. <meta http-equiv="content-type" content="text/html; charset=utf-8" /> Am i doing something wrong? Quote Link to comment https://forums.phpfreaks.com/topic/198111-php-mysql-problem-with-greek/#findComment-1040130 Share on other sites More sharing options...
Mchl Posted April 11, 2010 Share Posted April 11, 2010 Most likely. Your PHP script is converting these characters somewhere when storing data to database. Also, to properly store and retrieve non-latin characters in database using UTF-8 encoding, you have to set up several things: 1. Set up columns in your database to utf8 encoding (remembering to properly convert already stored data) 2. Set the database-PHP connection to UTF8 3. Set HTTP encoding header to utf8 Also converting your PHP and HTML sources to UTF-8 encoding might be necessary in some cases. This might be quite a lot of work for a larger project. Quote Link to comment https://forums.phpfreaks.com/topic/198111-php-mysql-problem-with-greek/#findComment-1040134 Share on other sites More sharing options...
solon Posted April 11, 2010 Author Share Posted April 11, 2010 Thanks Mchl, I think i got the idea and actually found the problem... The table chatset is latin for some reason! Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/198111-php-mysql-problem-with-greek/#findComment-1040139 Share on other sites More sharing options...
Mchl Posted April 11, 2010 Share Posted April 11, 2010 The reason being it used to be default MySQL encoding for a long time. Be aware, that just by changing this to utf8, you will not achieve much. Quote Link to comment https://forums.phpfreaks.com/topic/198111-php-mysql-problem-with-greek/#findComment-1040141 Share on other sites More sharing options...
solon Posted April 11, 2010 Author Share Posted April 11, 2010 Thank you, i will try to fix it based on your inputs! Quote Link to comment https://forums.phpfreaks.com/topic/198111-php-mysql-problem-with-greek/#findComment-1040145 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.