|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 19:00:02 2025 UTC | 
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.