Inserting Special Characters to MySQL using PHP September 20, 2006
Posted by ordinarywebguy in PHP.trackback
After reading about Character Encodings, I got a solution to one of my task:
function spEncode($string) {
return base64_encode($string);
}
function spDecode($string) {
$string = base64_decode($string);
}
/*** Inserting ***/
$MySQL = “INSERT INTO table (field) VALUES (‘”. spEncode($field) .”‘)”;
mysql_query($MySQL,$MyDB) or die(mysql_error());
/*** Retrieve **/
$MySQL = “SELECT field FROM table “;
$MyQuery = mysql_query($MySQL or die(mysql_error());
while($row = mysql_fetch_row($MyQuery)) {
$field = spDecode($row[0]);
}
print nl2br($field);
Problem solved!

Hey, almost two years later it worked for me too.. Seems that the ajax posts are always uft-8, and i’m using latin1, besides im having trouble with single quotes in textarea forms.. Econding seems to work fine, the fallback is it makes the sql table unreadable.. thanks
[...] 17, 2008 Posted by ordinarywebguy in MySQL, Uncategorized. trackback Regardless to my post about inserting special characters in mysql using PHP, this time we are not going to use PHP. Here’s [...]
Thanks a lot.
Arya