Jump to content

Saving UTF in sql via php - Help


Tuck

Recommended Posts

"-› ¿мαттнια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? ‹-"

Link to comment
https://forums.phpfreaks.com/topic/178502-saving-utf-in-sql-via-php-help/
Share on other sites

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')";

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 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? ‹-"

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" />

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? �-"

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? :/

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.