Rohit Pareek
Rohit Pareek

Reputation: 1563

weird characters in database

hi i need to store the weird character in my database but when i am trying to do so the weird character is replace with unknown character. i am giving you one example when i am try to enter in Sönke Wortmann in database it is stored as Sönke Wortmann. i want to store above text as same as it was.please tell me how can i do so

Upvotes: 0

Views: 234

Answers (1)

Rene Terstegen
Rene Terstegen

Reputation: 8046

You should use Unicode tables as well as a Unicode connection to your database.

Assuming you use MySQL:

Set the default character set of your table to utf8 and make sure the connection to your database is also using this character set:

$conn = mysql_connect($server, $username, $password);
mysql_set_charset("UTF8", $conn);

See also: https://www.php.net/manual/en/function.mysql-set-charset.php

Check the character set of your current connection with:

echo mysql_client_encoding($conn);

See also: https://www.php.net/manual/en/function.mysql-client-encoding.php

When creating your tables do something like this:

create table tableName (
    // Your table definition
) default charset = UTF8

If you have done these things and add weird characters to your table, you will see it is displayed correct.

Upvotes: 3

Related Questions