簡體   English   中英

phalcon phql在哪里找到帶有數組元素的查詢

[英]phalcon phql find query with array element in where

我正在使用phalcon的find查詢,並在where子句中使用數組元素,但出現錯誤

“''3'之前的掃描錯誤>:from_time:...'解析時:SELECT ...”

我有一個變通辦法,不使用phalcon的find,但想弄清楚,如何在where子句中使用數組元素,歡迎任何想法。 謝謝,塔爾

Phalcon(3.4.1版)

x86_64-pc-linux-gnu上的PostgreSQL 9.6.6,由gcc(GCC)4.8.3 20140911(Red Hat 4.8.3-9)編譯,64位

use Phalcon\Mvc\Model;
class Products extends Model
{

    public function initialize()
    {
        $this->setSource("products");
    }

    public function findByIdAndTime($id, $from_time)
    {
        $result = Products::find(["id=:id: AND create_time[3] > :from_time:",
        ['id' => $Id,'from_time' => $from_time]]);
        return $result;
    }
}

使用示例:

try
{
    $products = new Products();
    $products->findByIdAndTime(1, 1541672000);
}
catch(Exception $e)
{
    var_dump($e->getMessage());
}

postgre數據庫表列create_time的類型為integer [](在示例{1541600807,0,1541673916}中),$ from_time的值是先前從數據庫插入的now_time()(在示例中為1541672000)

這是如何創建表

CREATE TABLE public.products
(
    id int,
    create_time int[]
);

INSERT INTO products(create_time) VALUES ('{1541600807,0,1541673916}');

嘗試這個

public function findByIdAndTime($id, $from_time)
{
    $result = Products::find([
        'conditions' => 'id= :id: AND create_time[3] > :from_time:',
        'bind' => [
            'id' => $id,
            'from_time' => $from_time
        ]
    ]);

    return $result;  
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM