开发者

how to avoid encoding problems using ajax-json and php-postrgesql

i have problems with encoding when using json and ajax. chrome and ie encode umlauts as unicode when jsonifying, firefox and safari returning those utf-8 escaped umlauts like ¼Ã.

where is the best place to give all the same encoding? js / php-get or by writing them to the database.

开发者_高级运维and i think the next trouble is, when i reload the utf-8 encoded stuff from the db, and write them to the browser and then rewrite them to the db, again via ajax-request a get a real chaos?

can i avoid the chaous? can i handle the encoding in an easy way? pls. help :-)

very important is to also provide security


You must set everything to UTF-8, this means :

Database collation

Table collation

Field collation

Your coding software (example notepad++) encryption.


Had a similar problem. Maybe you are actually interpreting encoding the wrong way, clientwise. Try setting the frontend encoding before your queries.

<?php
$connection = pg_pconnect("dbname=data");
pg_set_client_encoding($connection, "encoding goes here"); //check enconding aletrnatives on PostgreSQL
$result = pg_query($connection, "SELECT whatever FROM wherever");
//and so on...
?>

I'm a newbie, but it may help. Also won't affect security in anyway if you are already protected against db injection.

Cheers

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜