我有一个查询,从ac_product
中提取一个项目,如下所示:
$STH = $DBH->prepare('SELECT * from ac_product where active = "1" and id = :id');
$STH->bindParam(':id', $value);
其中一个名为relationship的列包含0-n个需要提取的其他id。
现在的解决方案是每个id一个查询,如果可能的话,我希望将其限制为更少或只有一个。
例如考虑
$row['relationship'] //is 2.3.4
$arrayRelationship = explode(".",$row['relationship']);
是否有可能,如果有,如何进行PDO OR条件查询,以获取n个相关项?
或者,是否有一种平滑的方法可以编译n个查询,并至少使用beginTransaction和commit一次完成这些查询?
您可以使用IN((,这实际上是逻辑OR的替代品。
$sth = $dbh->prepare('SELECT * from ac_product where active = "1" and id IN (:id)');