drmg17928 2017-03-13 10:22
浏览 52
已采纳

Php问题与人物

I am building an app with Apache cordova for the support team for my company and everything was ok when I was using a test database in UTF8 was working.

Then when I was implement the real db I notice it was encoded with win-1252.

The problem is, even the db is with win-1252 we have many rows using special caracters like "ç" and "~" and "´" and "`" and with that when I am running the php all rows in the tables in my db will not show becasue of that.

Keep in mind I cann't convert the db to utf8.

ps:The solution I see is go to each row and remove that caracters but isn't a good solution(about 20,000 rows)

........................

PHP file:

header("Access-Control-Allow-Origin: *");

$dbconn = pg_connect("host=localhost dbname=bdgestclientes2 
    user=postgres password=postgres") 
    or die('Could not connect: ' . pg_last_error());

$data=array();

$q=pg_query($dbconn,"SELECT * FROM clientes WHERE idcliente = 3");

$row=pg_fetch_object($q)){$data[]=$row};

echo json_encode($data);

  • 写回答

3条回答 默认 最新

  • douweihui0178 2017-03-13 12:46
    关注

    I just needed to add a line in php to encode to unicode so I could use the data and display the way it is

    pg_set_client_encoding($dbconn, "UNICODE");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?