【发布时间】:2014-05-02 08:01:08
【问题描述】:
我需要从 DB 中读取一些我以这种方式有口音的值:“Cafetería”,真正的单词是“Cafetería”
当我将json传递给php脚本时,是这样的:
{"attribution":"CafeterÃa"}
$json = file_get_contents('php://input');
$json_post = json_decode($json, true);
$attribution = $json_post['attribution'];
但它读错了,并没有从 DB 中给我任何行。我使用 PDO 从 DB 中读取数据。
$db = new PDO("mysql:host=$hostDB;dbname=$nameDB;charset=UTF-8", $userDB, $passwordDB, array(PDO::ATTR_EMULATE_PREPARES => false,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
$stmt = $db->prepare("SELECT id, title, lat, lon FROM POI_Table WHERE attribution=:attribution");
$stmt->execute(array(':attribution'=>$attribution));
如果我在 HEIDI 中执行相同的查询,但将值完全按照 json 文件给出的方式写入,它就可以工作。在查询中使用前我应该如何转换值?
【问题讨论】: