PHP pg_query无法正常工作? [英] php pg_query not working?

查看:90
本文介绍了PHP pg_query无法正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是php和Postgresql的新手。当我尝试从数据库中检索数据时,查询似乎总是返回FALSE值。这是我的代码:

I'm very new to php and Postgresql. When I was trying to retrieve data from my database, the query seems to always return a FALSE value. Here is my code:

$dbconn = pg_connect("host=localhost port=5432 dbname=mydb user=user password=user")
if(!$dbconn) {
    echo "Not connected!";
}
$sql = 'SELECT * FROM "mytable"';
$query = pg_query($dbconn,$sql);
if(!$query) {
    echo "There is an error!";
    echo pg_last_error($dbconn);
}

因为未连接!没有打印出来,我很确定我的连接是正确的。但是,有错误!可以打印出来,但是pg_last_error()给了我一个空字符串。

Since the "not connect!" is not printed out, I'm quite sure my connection is correct. However, "There is an error!" is printed out, but pg_last_error() gives me an empty string.

是否存在将空字符串传回的原因,还有其他方法来检索错误消息?非常感谢!

Is there a reason why an empty string is passed back and is there other ways to retrieve the error message? Thanks a lot!

推荐答案

一切似乎都正确,因此我将执行以下操作:

Everything seems correct, so I would do the following:


  1. 确保 mytable存在并且有一些数据

  2. 连接到数据库后放置另一个pg_error:

例如

$dbconn = pg_connect("host=localhost port=5432 dbname=mydb user=user password=user");
var_dump($dbconn); // will it print "resource"?
echo pg_last_error($dbconn);

这篇关于PHP pg_query无法正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆