原生SQL联合查询数据,PHQL不支持union。
$sql = "(select s.* from oa_store s where s.other_name like '%广州%' order by s.sort asc)
union
(select s.* from oa_store s where s.other_name not like '%深圳%' order by
s.sort asc) limit 0,10";
$dbs = \Phalcon\DI::getDefault()->get('dbs');
$stmt = $dbs->prepare($sql);
$stmt->execute([]);
$oneResult = $stmt->fetchAll(\PDO::FETCH_ASSOC);
var_dump($oneResult);exit;
原生SQL跨库联表查询
$sql = "select c.name,g.phone from ecshop.ecs_recom c left join arshop.ar_goods g
on c.id=g.id where c.id=1";
$ecshopdb = \Phalcon\DI::getDefault()->get('ecshopdb');
$stmt = $ecshopdb->prepare($sql);
$stmt->execute([]);
$oneResult = $stmt->fetchAll(\PDO::FETCH_ASSOC);
var_dump($oneResult);exit;