php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54607 Warning on pg_connection_status()
Submitted: 2011-04-26 15:30 UTC Modified: 2011-05-29 11:03 UTC
From: sesebs at gmail dot com Assigned:
Status: Not a bug Package: PostgreSQL related
PHP Version: 5.2.6 OS: Ubuntu 8.04
Private report: No CVE-ID: None
 [2011-04-26 15:30 UTC] sesebs at gmail dot com
Description:
------------
In order to verify my connection to PostgreSql, I use PG_CONNECTION_STATUS(). When I try to check my connection, I have a warning who said : "pg_connection_status(): 103 is not a valid PostgreSQL link resource".
PG_CONNECTION_STATUS() should return just PGSQL_CONNECTION_BAD if the connection is not a valid PostgreSQL link ressource. Why there is a warning who appears ?

Test script:
---------------
$state = pg_connection_status($conn);
if ($state === PGSQL_CONNECTION_OK) {
  return true;
}

Actual result:
--------------
pg_connection_status(): 103 is not a valid PostgreSQL link resource

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-04-27 12:08 UTC] sesebs at gmail dot com
-PHP Version: 5.3.6 +PHP Version: 5.2.6
 [2011-04-27 12:08 UTC] sesebs at gmail dot com
Not PHP 5.3.6 but 5.2.6
 [2011-04-27 20:16 UTC] felipecg00 at gmail dot com
Seems like the problem is the resource $conn and not the function pg_connection_status().

It's like the function couldn't use that resource to do what it must to return the expected value.
 [2011-04-29 10:31 UTC] sesebs at gmail dot com
If the resource is not a valid PostgreSql link resource, pg_connection_status() return PGSQL_CONNECTION_BAD but in my case it generate a warning more. I'm catching the warning with a personalized error handler but I prefer keep the php error handler with a error_reporting() set to E_ALL. Is There is a solution to verify my connection without generate a warning ? Thanks.
 [2011-04-29 15:47 UTC] felipecg00 at gmail dot com
You are right. I have just tested it in a postgresql server right now and I don't get a warning from pg_connection_status(). Still, I am using version 5.3.3 of PHP.

But a strange behavior, is that my pg_connection_status returns boolean FALSE if resource is not valid, which is different from 0 of PGSQL_CONNECTION_BAD:

$valid_resource = pg_connect('host=~ valid string here');
$invalid_resource = null;

var_dump( pg_connection_status( $valid_resource ) ); // int(0) as expected
var_dump( pg_connection_status( $invalid_resource ) ); // bool(false)
var_dump( PGSQL_CONNECTION_BAD ); // int(1) different from bool(false)
var_dump( PGSQL_CONNECTION_OK ); // int(0) as expected
 [2011-05-29 11:03 UTC] iliaa@php.net
-Status: Open +Status: Bogus
 [2011-05-29 11:03 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

WHen the connection parameter is not a valid resource, the error comes from param 
validation...
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 08 06:01:28 2024 UTC