首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

pg_result_error

(PHP 4 >= 4.2.0, PHP 5, PHP 7)

pg_result_error - 获取与结果相关的错误消息

描述

代码语言:javascript
复制
string pg_result_error ( resource $result )

pg_result_error()返回与该result资源相关的任何错误消息。因此,用户比使用pg_last_error()获得正确的错误消息的机会更大。

函数pg_result_error_field()可以比pg_result_error()更详细地说明结果错误。

由于pg_query()FALSE在查询失败时返回,所以必须使用pg_send_query()和pg_get_result()来获取结果句柄。

参数

result

PostgreSQL查询结果资源,由pg_query(),pg_query_params()或pg_execute()等返回。

返回值

返回一个字符串。如果没有错误,则返回空字符串。如果存在与该result参数相关的错误,则返回FALSE

例子

示例#1 pg_result_error()示例

代码语言:javascript
复制
<?php
  $dbconn = pg_connect("dbname=publisher") or die("Could not connect");

  if (!pg_connection_busy($dbconn)) {
      pg_send_query($dbconn, "select * from doesnotexist;");
  }
  
  $res1 = pg_get_result($dbconn);
  echo pg_result_error($res1);
?>

扫码关注腾讯云开发者

领取腾讯云代金券