通过PHP检查pg_query_params的返回值 [英] Checking return value of pg_query_params by PHP

查看:162
本文介绍了通过PHP检查pg_query_params的返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在PHP的 pg查询参数

How can you check if a resource is false in PHP`s pg query params?

我运行以下代码失败

 $row = pg_num_rows ( $result );
 if ( $row !== 0 )
        echo "hurray";
 else
        echo "argh";

它给了我以下警告

Warning: pg_query_params() [function.pg-query-params]: Query failed: ERROR: invalid input syntax for integer: "" in /var/www/codes/index.php on line 120

我使用 $ dbconn 是正确的因此第二个警告似乎只是一种症状。
的原因是整数的无效类型。

I use $dbconn which is correct so the the second warning seems to be only a sympton. The cause of this is the invalid type for an integer.

我的查询是这个

$dbconn = pg_connect("host=localhost port=5432 dbname=masi user=masi password=123");
$result = pg_query_params ( $dbconn,
    'SELECT question_id
    FROM questions
    WHERE question_id = $1',
    array ( $question_id )
);


推荐答案

尝试一下:

$result = @pg_query_params($dbconn, "SELECT * FROM SOME_TABLE", array());
if($result !== FALSE)
{
  $row = @pg_num_rows($result);
  if ( $row !== 0 )
         echo "hurray";
  else
         echo "argh";
}
else
{
  echo "Seems, your query is bad.";
}

在使用$ result之前,需要检查它。

Before you use $result, you need check it.

这篇关于通过PHP检查pg_query_params的返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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