Tuck Posted October 21, 2009 Share Posted October 21, 2009 "-› ¿мαттнιαs? ‹-" is the string i set my sql db to be utf8_bin but well do i have to replace some chars before saving it into sql i got str_replace() to replace ' with \' (this is just an example) could anyone show me :/ Saving it direct into database like that will be viewed correct with sql db viewer but, retrieving it with sql will display "-› ¿???????s? ‹-" Quote Link to comment https://forums.phpfreaks.com/topic/178502-saving-utf-in-sql-via-php-help/ Share on other sites More sharing options...
MadTechie Posted October 21, 2009 Share Posted October 21, 2009 I'm not sure what your asking... i have to replace some chars before saving it into sql i got str_replace() to replace ' with \' Don't do a str_replace to replace ' with \', use mysql_real_escape_string $string = mysql_real_escape_string($string); $query = "INSERT INTO `table` (`string`) VALUES ('$string')"; Quote Link to comment https://forums.phpfreaks.com/topic/178502-saving-utf-in-sql-via-php-help/#findComment-941322 Share on other sites More sharing options...
cags Posted October 21, 2009 Share Posted October 21, 2009 I suspect the question should read something along the lines of "How do I succesfully store crylic characters in an SQL database? And how would I output this information?" Have you checked the database with PHPMyAdmin to see if the characters appear correct? It's probable that the displaying isn't working properly because of the character encoding on the page your trying to echo the characters out to. Quote Link to comment https://forums.phpfreaks.com/topic/178502-saving-utf-in-sql-via-php-help/#findComment-941325 Share on other sites More sharing options...
Tuck Posted October 21, 2009 Author Share Posted October 21, 2009 I suspect the question should read something along the lines of "How do I succesfully store crylic characters in an SQL database? And how would I output this information?" Have you checked the database with PHPMyAdmin to see if the characters appear correct? It's probable that the displaying isn't working properly because of the character encoding on the page your trying to echo the characters out to. i tried to save them from phpmyadmin.. Read: Saving it direct into database like that will be viewed correct with sql db viewer but, retrieving it with sql will display "-› ¿???????s? ‹-" Quote Link to comment https://forums.phpfreaks.com/topic/178502-saving-utf-in-sql-via-php-help/#findComment-941330 Share on other sites More sharing options...
cags Posted October 21, 2009 Share Posted October 21, 2009 So as I said the character encoding on the page isn't correct. You need to set the content type header, either by use of the header function or through HTML. <meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" /> Quote Link to comment https://forums.phpfreaks.com/topic/178502-saving-utf-in-sql-via-php-help/#findComment-941335 Share on other sites More sharing options...
MadTechie Posted October 21, 2009 Share Posted October 21, 2009 Cont. from cags PHP option header('Content-type: text/html; charset=utf-8'); Quote Link to comment https://forums.phpfreaks.com/topic/178502-saving-utf-in-sql-via-php-help/#findComment-941338 Share on other sites More sharing options...
Tuck Posted October 21, 2009 Author Share Posted October 21, 2009 So as I said the character encoding on the page isn't correct. You need to set the content type header, either by use of the header function or through HTML. <meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" /> now displays "-� �???????s? �-" Quote Link to comment https://forums.phpfreaks.com/topic/178502-saving-utf-in-sql-via-php-help/#findComment-941351 Share on other sites More sharing options...
Tuck Posted October 21, 2009 Author Share Posted October 21, 2009 now displays "-� �???????s? �-" where it should be "-› ¿мαттнιαs? ‹-" is there a prober way i should read it from sql? Quote Link to comment https://forums.phpfreaks.com/topic/178502-saving-utf-in-sql-via-php-help/#findComment-941362 Share on other sites More sharing options...
cags Posted October 21, 2009 Share Posted October 21, 2009 Check out this thread. Quote Link to comment https://forums.phpfreaks.com/topic/178502-saving-utf-in-sql-via-php-help/#findComment-941366 Share on other sites More sharing options...
Tuck Posted October 21, 2009 Author Share Posted October 21, 2009 I did a quick search and came across somebody that claims this solved their problem using... mysql_query("SET CHARACTER SET utf8"); mysql_query("SET NAMES utf8"); ... which is a slight addition to nrobi's suggestion. $result = mysql_query("SELECT * FROM `lottery` WHERE `STEAM`='${LSTEAM}' AND `ID`>'1'"); show me an example how i would include it there? :/ Quote Link to comment https://forums.phpfreaks.com/topic/178502-saving-utf-in-sql-via-php-help/#findComment-941374 Share on other sites More sharing options...
cags Posted October 21, 2009 Share Posted October 21, 2009 er.... mysql_query("SET CHARACTER SET utf8"); mysql_query("SET NAMES utf8"); $result = mysql_query("SELECT * FROM `lottery` WHERE `STEAM`='${LSTEAM}' AND `ID`>'1'"); Quote Link to comment https://forums.phpfreaks.com/topic/178502-saving-utf-in-sql-via-php-help/#findComment-941376 Share on other sites More sharing options...
Tuck Posted October 21, 2009 Author Share Posted October 21, 2009 er.... mysql_query("SET CHARACTER SET utf8"); mysql_query("SET NAMES utf8"); $result = mysql_query("SELECT * FROM `lottery` WHERE `STEAM`='${LSTEAM}' AND `ID`>'1'"); though u ment it needed to be included in the mysql_query of result ;/ trying it now Quote Link to comment https://forums.phpfreaks.com/topic/178502-saving-utf-in-sql-via-php-help/#findComment-941378 Share on other sites More sharing options...
MadTechie Posted October 21, 2009 Share Posted October 21, 2009 Personally i have mysql_query("SET CHARACTER SET utf8"); mysql_query("SET NAMES utf8"); on the same place as connection to the database Quote Link to comment https://forums.phpfreaks.com/topic/178502-saving-utf-in-sql-via-php-help/#findComment-941383 Share on other sites More sharing options...
cags Posted October 21, 2009 Share Posted October 21, 2009 Personally i have mysql_query("SET CHARACTER SET utf8"); mysql_query("SET NAMES utf8"); on the same place as connection to the database Yer, that would obviously be more sensible than before each query. I wasn't intending to be literal. Quote Link to comment https://forums.phpfreaks.com/topic/178502-saving-utf-in-sql-via-php-help/#findComment-941390 Share on other sites More sharing options...
MadTechie Posted October 21, 2009 Share Posted October 21, 2009 LOL, I kinda guess your know cags, it was more a comment for Tuck Quote Link to comment https://forums.phpfreaks.com/topic/178502-saving-utf-in-sql-via-php-help/#findComment-941396 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.