Question

I tried to insert Hebrew a text value into a column, But it changes the value to Gibberish. An example of that:

mssql_query ("UPDATE TABLE SET COLUMON = N'בדיקה'");

As you can assume, It changes the value of the column, But the value changed to ????? and if I try to do it from Query Analyser it works fine.

My column's collation is HEBREW_CI_AS. How can I fix this?

Was it helpful?

Solution 2

I solve this problem if someone else has this problem here is my way to fix that:

  1. Create a new database for this specific table or else tables for your web.
  2. Set Hebrew_CI_AS as collation (everyone to what he created).
  3. In your PHP code use mb_convert_encoding() function for SELECT and INSERT.

OTHER TIPS

You need to specify collation preperty for the string in the INSERT statement you are using. Also the string you are inserting should be of UNICODE datatype - use N prefix for that.

INSERT INTO MEMB_INFO (User, Pass, Name) VALUES ('Joni', '123456', N'גוני דף' COLLATE HEBREW_CI_AS)

Check that PHP variable can handle unicode characters. Otherwise it will be PHP that turns your string into question marks.

You may check out SQL Server drivers for PHP. And Unicode Character Properties from PHP doicumentation.

Some resources on PHP and unicode:

http://www.sitepoint.com/bringing-unicode-to-php-with-portable-utf8/

http://php.net/manual/en/function.utf8-encode.php

http://allseeing-i.com/How-to-setup-your-PHP-site-to-use-UTF8

http://www.yiiframework.com/wiki/16/how-to-set-up-unicode/

http://pageconfig.com/post/portable-utf8

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top