最近在使用postgresql数据库的json格式,发现pdo查询报错
源码如下
<?php
// 使用PDO链接
$pdo = new PDO("pgsql:host=127.0.0.1;port=5432;dbname=postgres","postgres","");
$statement = $pdo->prepare("select * from test where account::jsonb ? '111'");
$statement->execute();
var_dump($statement->errorInfo());
$rs = $statement->fetch();
var_dump($rs);
// 原生链接 查询
$p = pg_connect("host=127.0.0.1 port=5432 dbname=postgres user=yluchao password=''");
$rs = pg_query($p, "select * from test where account::jsonb ? '111'");
var_dump(pg_fetch_all($rs));
/*create table test
(
id bigserial primary key,
account jsonb not null default '{}',
name varchar(255) not null default ''
);*/
如图 使用pdo查询报错,使用原生的pgsql链接则可以查询
2 回答
慕无忌1623718
TA贡献1744条经验 获得超4个赞
PDO 占位符写的有问题,不知道这个test 表数据结构是怎么样的
// 使用PDO链接
$pdo = new PDO("pgsql:host=127.0.0.1;port=5432;dbname=postgres","postgres","");
$statement = $pdo->prepare("select * from test where account = ?");
$statement->execute(array(111));
var_dump($statement->errorInfo());
$rs = $statement->fetch();
var_dump($rs);
- 2 回答
- 0 关注
- 456 浏览
添加回答
举报
0/150
提交
取消