Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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