【发布时间】:2015-01-26 09:32:27
【问题描述】:
我在这样的数据库中有法国城市:
01001 Abergement-Clémenciat
01002 Abergement-de-Varey
01004 Ambérieu-en-Bugey
01005 Ambérieux-en-Dombes
01006 Ambléon
01007 Ambronay
01008 Ambutrix
01009 Andert-et-Condon
01010 Anglefort
我有一个 PDO 准备查询:
$sth = $this->connection->prepare('
SELECT code
FROM insee
WHERE city = :city
');
$sth->bindParam(':city', $city, PDO::PARAM_STR);
$sth->execute();
$row = $sth->fetch();
当 city 等于“Ambronay”或“Ambléon”或“Ambutrix”时,fetch 正在返回一些东西。 但是当 city 等于 "Abergement-de-Varey" 或 "Saint-Étienne" 或带有破折号 (-) 的其他内容时,当数据在数据库中时,fetch 不会返回任何内容。
可能是什么原因?
感谢您的提前。
【问题讨论】:
-
尝试转义破折号:
$city = preg_replace("/\-/", '\-', $city); -
谢谢,但结果是一样的。提取没有返回任何内容。