php - phalcon phql 在 where 中查找带有数组元素的查询
问题描述
我正在使用 phalcon 的查找查询,并在 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 DB 表列 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;
}
推荐阅读
- c# - ASP.NET MVC 通用存储库实现和使用
- javascript - Axios FormData()获取空对象
- python - Jupyter 笔记本因“内核没有响应”而失败
- python-3.x - Python:将目录从远程机器(Linux/Windows)复制到本地机器(Windows)
- python - Matlab 到 Python 的转换:“poissinv”函数
- python - 如何在 MyHDL 中接收输入总线?
- typescript - 将表单 TypeScript 1.8.10 升级到 3.1.6
- css - 问题 Firefox 文本溢出:子元素上的省略号
- bash - 如何仅检测我的 bash shell 脚本中的不同文件?
- php - 有没有人经历过 Laravel Artisan 命令返回开放
我一直在用最新版本的 Laravel 框架(目前为 5.7)组合一个 Web 应用程序,我注意到 Artisan 功能存在一个相当令人沮丧的错误。
例如,当我运行 php artisan migrate 时,我得到以下示例响应:
<?php nothing to migrate