这将返回结果:
$query = $dbh->prepare('SELECT * FROM groups WHERE id LIKE :id ORDER BY id');
$query->bindValue(':id', $this->id.'_');
这不会:
$query = $dbh->prepare('SELECT g.*, d.desc_text FROM groups g LEFT JOIN descriptions d ON d.desc_id=g.id WHERE g.id LIKE :id AND d.desc_type=1 ORDER BY g.id');
$query->bindValue(':id', $this->id.'_');
然而,如果我在 WebMin 中运行下面的 SQL 查询(“0002_”是上面绑定的值),那么我会得到结果。
SELECT g.*, d.desc_text FROM groups g LEFT JOIN descriptions d ON d.desc_id=g.id WHERE g.id LIKE "0002_" AND d.desc_type=1 ORDER BY g.id
那么为什么 PDO 不喜欢我上面第二段代码中的查询呢?