php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52682 pg_query does not return on error
Submitted: 2010-08-24 00:52 UTC Modified: 2013-02-18 00:34 UTC
Votes:5
Avg. Score:4.8 ± 0.4
Reproduced:5 of 5 (100.0%)
Same Version:2 (40.0%)
Same OS:3 (60.0%)
From: benoitg at coeus dot ca Assigned:
Status: No Feedback Package: PostgreSQL related
PHP Version: 5.3.3 OS: Ubuntu Lucid or Maverick
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: benoitg at coeus dot ca
New email:
PHP Version: OS:

 

 [2010-08-24 00:52 UTC] benoitg at coeus dot ca
Description:
------------
pg_query() should return when an SQL error happens (there are then various function to get the error description.  However in php 5.3.2 (ubuntu lucid) and 5.3.3 (ubuntu maverick), the function doesn't return at all (the php script ends).

Included is a short test script.  As will run on ubuntu as written if you run php cli as the postgres system user, for example:

sudo -u postgres php test_pg_query_not_returning.php

Test script:
---------------
<?php

define ('CONF_DATABASE_NAME', "postgres");
define ('CONF_DATABASE_USER', "postgres");
define ('CONF_DATABASE_PASSWORD', "");
$conn_string = "dbname=".CONF_DATABASE_NAME." user=".CONF_DATABASE_USER." password=".CONF_DATABASE_PASSWORD."\n";
$conn = pg_connect($conn_string) or die("Unable to connect to database, fix this first");

echo "About to execute actual test: \n";
$sql = "SOME INVALID SQL";
$return = pg_query($conn, $sql);

if($return === FALSE) {
        echo "You should see this, but this code is never executed!\n";
}

echo "Even this code is never executed!\n";
?>


Expected result:
----------------
sudo -u postgres php test_pg_query_not_returning.php 
About to execute actual test: 
PHP Warning:  pg_query(): Query failed: ERROR:  syntax error at or near "SOME"
LINE 1: SOME INVALID SQL
        ^
 in /var/www/eureka/html/tests/test_pg_query_not_returning.php on line 11
You should see this, but this code is never executed!
Even this code is never executed!

Actual result:
--------------
sudo -u postgres php test_pg_query_not_returning.php 
About to execute actual test: 
PHP Warning:  pg_query(): Query failed: ERROR:  syntax error at or near "SOME"
LINE 1: SOME INVALID SQL
        ^
 in /var/www/eureka/html/tests/test_pg_query_not_returning.php on line 11


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-08-25 23:17 UTC] benoitg at coeus dot ca
Additional notes:

When the bug occurs, lines like the following are written to the postgresql log:
2010-08-25 17:03:03 EDT LOG:  unexpected EOF on client connection

No errors are reported by apache.
 [2010-09-20 14:32 UTC] iliaa@php.net
-Status: Open +Status: Feedback
 [2010-09-20 14:32 UTC] iliaa@php.net
Seems to work fine in latest snapshot.
 [2010-10-19 17:23 UTC] Dalifter2006 at mail dot ru
php --version
PHP 5.3.3-1ubuntu9 with Suhosin-Patch (cli) (built: Sep 20 2010 22:40:29) 
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans

Catched up on selection from not-exists table.
 [2010-10-20 13:21 UTC] jr at jr dot pl
I have the same on Ubuntu 
Linux  2.6.35-22-server #35-Ubuntu SMP x86_64 GNU/Linux
and PHP version 5.3.3-1ubuntu9 

that works fine on PHP 5.3.2-1ubuntu4.5
 [2013-02-18 00:34 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Nov 27 05:03:20 2021 UTC