timski72 Posted December 7, 2012 Share Posted December 7, 2012 Hi Guys, I have a test database with a record in it where the field "requested" is set to "η μητερa" (Greek characters, i.e. unicode) If I perform the following query in phpMyAdmin "SELECT syllabilized FROM transliterated WHERE requested = η μητερa" I get the expected result. This query doesn't seem to be working within my php script however. I am not sure if it is due to my php code (which is very newby) or a problem with de/encoding unicode. Here is the my scripts (truncated) with the $input hardcoded for testing. I've tested with $_POST['greek'] posting from the website and hardcoded when debugging in phpDesigner but neither is working. I get a result so it goes into the else statement but the output is blank. <?php ini_set('default_charset', 'UTF-8'); mb_internal_encoding("UTF-8"); // $input = $_POST['greek']; $input = "η μητερa"; $connection = mysqli_connect($host, $user, $passwd, $dbname) or die(mysqli_error()); $query = "SELECT syllabilized FROM transliterated WHERE requested = '$input'"; $result = mysqli_query($connection, $query) or die($query); if (!$result) { // NO CODE FOR THIS SECTION YET } else { $row = mysqli_fetch_row($result); $syllablized == $row[2]; $input == $syllablized; echo $input; } ?> Here is the content and structure of the database. requested generated syllabilized modified create edit η μητερa ee meetehrah ee mee-teh-rah No 18/02/2010 16:45 19/02/2010 16:46 So I'm expecting the user to enter η μητερa and get ee mee-teh-rah back. Any tips would be very welcome. Thanks, Tim. Quote Link to comment https://forums.phpfreaks.com/topic/271723-trying-to-find-a-match-in-database-but-data-is-stored-in-unicode/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 7, 2012 Share Posted December 7, 2012 After you make your database connection, add the following line of code and see if it corrects the problem - mysqli_set_charset($connection, "utf8"); Also, $row[2] in the fetched $row array doesn't exist (unless you also altered your query for the post), since you are only selecting the syllabilized column. Try $row[0]. Quote Link to comment https://forums.phpfreaks.com/topic/271723-trying-to-find-a-match-in-database-but-data-is-stored-in-unicode/#findComment-1398132 Share on other sites More sharing options...
timski72 Posted December 7, 2012 Author Share Posted December 7, 2012 Thanks for you reply. I modified the code incorporating your suggestions as below. $syllabilized is still blank. Tim. <?php ini_set('default_charset', 'UTF-8'); mb_internal_encoding("UTF-8"); // $input = $_POST['greek']; $input = "η μητερa"; $connection = mysqli_connect($host, $user, $passwd, $dbname) or die(mysqli_error()); mysqli_set_charset($connection, "utf8"); $query = "SELECT syllabilized FROM transliterated WHERE requested = '$input'"; $result = mysqli_query($connection, $query) or die($query); if (!$result) { // NO CODE FOR THIS SECTION YET } else { $row = mysqli_fetch_row($result); $syllablized == $row[0]; echo syllablized; ?> Quote Link to comment https://forums.phpfreaks.com/topic/271723-trying-to-find-a-match-in-database-but-data-is-stored-in-unicode/#findComment-1398141 Share on other sites More sharing options...
PFMaBiSmAd Posted December 7, 2012 Share Posted December 7, 2012 $syllablized == $row[0]; Two == signs is a equal comparison operator. One = sign is an assignment operator. Quote Link to comment https://forums.phpfreaks.com/topic/271723-trying-to-find-a-match-in-database-but-data-is-stored-in-unicode/#findComment-1398142 Share on other sites More sharing options...
timski72 Posted December 7, 2012 Author Share Posted December 7, 2012 Thank you so much. I wouldn't have spotted it. Sometimes you can't see the wood for the trees :-) Works great now :-) Quote Link to comment https://forums.phpfreaks.com/topic/271723-trying-to-find-a-match-in-database-but-data-is-stored-in-unicode/#findComment-1398148 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.