|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32223 weird behaviour of pg_last_notice
Submitted: 2005-03-07 18:13 UTC Modified: 2005-11-07 14:02 UTC
Avg. Score:4.7 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:0 (0.0%)
From: valiak at gmail dot com Assigned: helly (profile)
Status: Closed Package: PostgreSQL related
PHP Version: 5CVS-2005-10-10 OS: *
Private report: No CVE-ID: None
 [2005-03-07 18:13 UTC] valiak at gmail dot com
i've tried to localize to as smallest code as I could
the correct result happens even if you comment the include line or the global directive or not using exceptions ... (there are few other modifications too)

it happens with the cli version and with the apache module version

ceco@base ~/tmp/pg_last_notice
$ php -v
PHP 5.0.3 (cli) (built: Mar  2 2005 13:13:40)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v2.0.3, Copyright (c) 1998-2004 Zend Technologies

compiled with
./configure --with-gettext --with-oci8 --with-apxs=/usr/bin/apxs --with-gd --with-pgsql --with-readline --with-zlib --with-mysql=/usr --with-
jpeg-dir --with-png-dir --enable-mbstring --enable-sockets --enable-pcntl --enable-sigchild --with-exec-dir=/usr/bin --with-config-file-path=


PostgreSQL Support => enabled
PostgreSQL(libpq) Version => 8.0.1
Multibyte character support => enabled
SSL support => disabled
Active Persistent Links => 0
Active Links => 0

Directive => Local Value => Master Value
pgsql.allow_persistent => Off => Off
pgsql.auto_reset_persistent => Off => Off
pgsql.ignore_notice => Off => Off
pgsql.log_notice => Off => Off
pgsql.max_links => Unlimited => Unlimited
pgsql.max_persistent => Unlimited => Unlimited

if some more info is needed tell me what to do?

Reproduce code:
ceco@base ~/tmp/pg_last_notice
$ cat
ceco@base ~/tmp/pg_last_notice
$ cat test.php

this is a dummy pg function just to raise notice, called from this file

        RAISE NOTICE '11111';
        return 'f';
$$ LANGUAGE plpgsql;

        define(TTT, pg_connect('user=test password=test dbname=test'));
        include_once '';

function tester() {
        global $t;
        $res = pg_query(TTT, 'SELECT test_notice()');
        $result = pg_fetch_row($res, 0);
        if ($result[0] == 'f') {
          throw new Exception(pg_last_notice(TTT));

try {
echo tester();
echo 2;
catch (Exception $e) {
  echo $e->getMessage(), 1;


Expected result:
ceco@base ~/tmp/pg_last_notice
$ php test.php
NOTICE:  111111

Actual result:
ceco@base ~/tmp/pg_last_notice
$ php test.php


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-03-08 13:28 UTC] valiak at gmail dot com
if you switch the places of include_once and define there is no bug

there is no difference in the behaviour if include_once is changed to include or require_once or require
 [2005-08-30 13:05 UTC]
Please try using this CVS snapshot:
For Windows:

And set error_reporting to E_ALL..

 [2005-09-02 14:48 UTC] valiak at gmail dot com
still do not work correctly, there is no output even with 
 [2005-09-23 15:55 UTC] valiak at gmail dot com
the code snipped is presented in the bug report and is    
quite easily reproduced on any machine with postgresql and    
php5 I have tried, there were some other users confirming 
the problem, but are deleted from the bug report. 
It has "external resources such as databases, etc." 
because it is a database related bug!! 
I use "Short tags" because it is written here   
that I can use them.  
Anyway ......... here is even more short version of the 
(but still with external resources!!! and two files) // the main 
file // the 
include // the database 
schema - only one function
 [2005-09-24 20:36 UTC]
Assigned to the maintainer.

 [2005-10-09 18:07 UTC]
I made up a php test script for this: ext/pgsql/tests/80_bug32223.phpt

But i cannot reproduce your behavior with 5.1-dev or HEAD.

Maybe it is postgres?

marcus=# select version();
 PostgreSQL 8.0.1 on i586-mandrake-linux-gnu, compiled by GCC i586-mandrake-linux-gnu-gcc (GCC) 3.4.3 (Mandrakelinux 10.2 3.4.3-7mdk)

Works in all versions for me. So please try the following:
php run-tests.php ext/pgsql/tests/80_bug32223.phpt

If that fails, can you do a 'memcheck' on that?

And tell me your postgres version.
 [2005-10-10 12:24 UTC] valiak at gmail dot com
i tried with the new version problem still exists (it does not exists in version 4)

your script differs from the one I have posted, the main difference is that I use constant to store the return value of pg_connect, the code is in funcion, and the include must appear bellow pg_connect, try this test:

Bug #32223 (weird behaviour of pg_last_notice)

@pg_query($conn, "CREATE LANGUAGE 'plpgsql' HANDLER plpgsql_call_handler LANCOMPILER 'PL/pgSQL'");
$res = @pg_query($conn, "CREATE OR REPLACE FUNCTION test_notice() RETURNS boolean AS '
        RAISE NOTICE ''11111'';
        return ''f'';
' LANGUAGE plpgsql;");
if (!$res) die('skip PLPGSQL not available');


define ('dbh', pg_connect($conn_str));


if (!dbh) {
        die ("Could not connect to the server");

//@pg_query(dbh, "CREATE LANGUAGE 'plpgsql' HANDLER plpgsql_call_handler LANCOMPILER 'PL/pgSQL'");
$res = pg_query(dbh, "CREATE OR REPLACE FUNCTION test_notice() RETURNS boolean AS '
        RAISE NOTICE ''11111'';
        return ''f'';
' LANGUAGE plpgsql;");

function tester() {
        $res = pg_query(dbh, 'SELECT test_notice()');
        $row = pg_fetch_row($res, 0);
        if ($row[0] == 'f')


array(1) {
  string(1) "f"
string(14) "NOTICE:  11111"
 [2005-10-10 12:25 UTC]
 [2005-11-07 13:58 UTC]
The extension code used an unnecessary indirection which was only a problem in your case.
 [2005-11-07 14:02 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

Fixed in 4.4.2-dev, 5.1.0RC4-dev, HEAD
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jun 18 22:01:29 2024 UTC