有一个Phalcon
查询:
function lireParCritere($critere) {
$sSQL = "
SELECT c.salle_code,c.salle_lib,c.salle_comment
FROM salle as c WHERE 1 = 1 ";
if(isset($critere["salle_code"]) && $critere["salle_code"] != "") {
$sSQL .= "AND c.salle_code = ' " . $critere["salle_code"] . "' ";
}
$query = new Query($sSQL,$this->getDI());
$ret = $query->execute();
return $ret;
}
如何打印此query
的结果?
答案 0 :(得分:1)
\Phalcon\Mvc\Model\Query
使用PHQL,而不是SQL。
public function lireParCritere($critere)
{
$model = '\Namespaced\Path\To\Salle';
$sSQL = "
SELECT c.salle_code,c.salle_lib,c.salle_comment
FROM $model as c WHERE 1 = 1 ";
if(isset($critere["salle_code"]) && $critere["salle_code"] != "") {
$sSQL .= "AND c.salle_code = ' " . $critere["salle_code"] . "' ";
}
$query = new \Phalcon\Mvc\Model\Query($sSQL, $this->getDI());
$ret = $query->execute();
return $ret;
}
public function test()
{
foreach ($this->lireParCritere([]) as $row) {
/** @var \Phalcon\Mvc\Model\Row $row */
assert($row->salle_code === $row->readAttribute('salle_code'));
}
}