[英]How to find by multiple criteria with Phalcon findFirst?
我正在嘗試從我的視頻數據庫中獲取視頻,選擇基於external_id
和language_id
(兩個整數)的唯一組合。 我嘗試了下面的代碼,但看起來像findFirst()
只能獲得第一個標准
$video = Video::findFirst("language_id=" . $language->id . " and external_id=" . $external->id);
任何人都可以幫助我如何正確使用具有多個標准的findFirst?
嘗試綁定您的參數與連接它們。 更安全,它可能會識別錯誤區域
$video = Video::findFirst(
[
'columns' => '*',
'conditions' => 'language_id = ?1 AND external_id = ?2',
'bind' => [
1 => $language->id,
2 => $external->id,
]
]
);
find()和findFirst()方法都接受指定搜索條件的關聯數組:
$robot = Robots::findFirst(array(
"type = 'virtual'",
"order" => "name DESC",
"limit" => 30
));
$robots = Robots::find(array(
"conditions" => "type = ?1",
"bind" => array(1 => "virtual")
));
// What's the first robot in robots table?
$robot = Robots::findFirst();
echo "The robot name is ", $robot->name, "\n";
// What's the first mechanical robot in robots table?
$robot = Robots::findFirst("type = 'mechanical'");
echo "The first mechanical robot name is ", $robot->name, "\n";
// Get first virtual robot ordered by name
$robot = Robots::findFirst(array("type = 'virtual'", "order" => "name"));
echo "The first virtual robot name is ", $robot->name, "\n";
繼續閱讀: 主要文件 - 查找記錄
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.