-1

I would like to insert/read Arabic words into mysql database

When I insert Arabic words from Chrome, I see them in DB ASCII
When I insert from FireFox, I see them in DB Unicode
See this picture from my DB: http://postimg.org/image/6ht95v671/

I need everything to be inserted in ASCII only

Note: I insert only from php form using POST method

Ahmed
  • 255
  • 2
  • 7
  • 17

2 Answers2

1

For each new table you create, during creation, set its default character set to UTF8 and you should be good to go:

Here are the full docs

And here is some example sql

CREATE TABLE my_great_table('some_column' VARCHAR(1024)) DEFAULT CHARACTER SET = utf8;

Arabic characters can't be written in ASCII. It's an 8 bit character set that quite literally does not have the room to insert anymore characters into it besides 0-9, a-z, A-Z, punctuation, and some invisible command characters.

Here's a chart on ascii

Zarathuztra
  • 3,215
  • 1
  • 20
  • 34
0

You could always convert it to hex before putting it in the database

function strToHex($string){
    $hex='';
    for ($i=0; $i < strlen($string); $i++){
        $hex .= dechex(ord($string[$i]));
    }
    return $hex;
}

and then get the values by converting the hex to string

function hexToStr($hex){
    $string='';
    for ($i=0; $i < strlen($hex)-1; $i+=2){
        $string .= chr(hexdec($hex[$i].$hex[$i+1]));
    }
    return $string;
}
FlameBlazer
  • 1,592
  • 2
  • 10
  • 9