php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22221 bad rows count in the result object for postgresql
Submitted: 2003-02-14 06:27 UTC Modified: 2003-02-19 07:33 UTC
From: alex dot madon at bestlinuxjobs dot com Assigned: mboeren (profile)
Status: Closed Package: DBX related
PHP Version: 4.2.2 OS: Linux morlupo 2.4.18-14 (redhat
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: alex dot madon at bestlinuxjobs dot com
New email:
PHP Version: OS:

 

 [2003-02-14 06:27 UTC] alex dot madon at bestlinuxjobs dot com
Hello,
I am using the default php modules with postgresql coming with redhat 8.0.

I have a code using the dbx function that work well in mysql.
When changing to postgresql (i.e. changing DBX_MYSQL to DBX_PGSQL in function dbx_connect()) I get warnings that I don't get with mysql.
Note that those warning are difficult to see: you have to define your own error_handler to see them!!!
That's what I do usually on my web sites.
In your error handler I have set the following message options:
(E_ERROR,E_WARNING,E_PARSE,E_CORE_ERROR,E_CORE_WARNING,E_USER_ERROR, E_USER_WARNING)

--------------------


OK, with that set up

after making a query that return 3 rows I get the message:
-------
pg_fetch_array() unable to jump to row 10 on PostgreSQL result index 4
in /somepath/library_connect.php line 68
-------
this corresponds to the following loop:

$query="select * from membership";
$result=dbx_query($socket,$query,DBX_RESULT_ASSOC);
$num_rows = $result->rows; 

for ($i=0;$i<$num_rows;$i++) {
    list(,$row)=each($result->data);
}

This type of code works well with the mysql driver. In postgresq it seems it looks for indexes for 0 to 10 included!


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-02-14 06:32 UTC] alex dot madon at bestlinuxjobs dot com
sorry for the typo:
please read:
after making a query that return *10* rows I get the message:
-------
pg_fetch_array() unable to jump to row 10 on PostgreSQL result index 4
in /somepath/library_connect.php line 68
 [2003-02-14 06:44 UTC] mboeren@php.net
Internally in the dbx_pgsql driver, the code disables E_WARNING for pg_fetch_array, fetches rows until no more rows are available (this is detected by trapping the warning you got), then re-enables the E_WARNING if it was enabled in the first place.
This is probably why you have to define your own error-handler to see the warning at all.

Does this happen with any user-defined error-handler or is your setup very specific? Is there an easy workaround without resorting to @dbx_qeuery()? Could you post the code for your error-handler (simplified if possible)?

Thanks, Marc.

 [2003-02-14 07:26 UTC] alex dot madon at bestlinuxjobs dot com
Hello Marc,
Thank you for replying so fast.

I don't think my setup is very specific.
Here is the code of my error handler.
(Note that the work around I have found is to regexp the $errormesg: I didn't want to leave completely the E_WARNING completely as a SQL syntax error will be unnoticed by me. Strangely a SQL syntax erro comes out with the same error code E_WARNING as this postgresql "bug")
I don't know how the default handler do, but it catches the SQL errors but not this postgresql stuff.... perhaps does the same thing: parse for ERROR)


---- here is the code-----
function userErrorHandler ($errno, $errmsg, $filename, $linenum, $vars) {
    # define an assoc array of error string
    # in reality the only entries we should
    # consider are 2,8,256,512 and 1024
    $errortype = array (
			1   => "Error",
			2   => "Warning",
			4   => "Parsing Error",
			8   => "Notice",
			16  => "Core Error",
			32  => "Core Warning",
			64  => "Compile Error",
			128 => "Compile Warning",
			256 => "User Error",
			512 => "User Warning",
			1024=> "User Notice"
			);

    # set of errors for which we will die
    $die_errors = array(E_USER_ERROR);
    
    # set of errors that will be mailed
    $mail_errors = array(E_ERROR,E_WARNING,E_PARSE,E_CORE_ERROR,E_CORE_WARNING,E_USER_ERROR, E_USER_WARNING);
    
    
    $err.=$errortype["$errno"]." (bit $errno)\n$errmsg\nin $filename line $linenum";
    
    if (in_array($errno, $mail_errors) && preg_match("/ERROR/",$errmsg)) {
	myerrormail("error@bestlinuxjobs.com",$errortype["$errno"]." (bit $errno)",$err);
    }
    #possibly die
    if (in_array($errno, $die_errors)){
        exit;
    }
    return 1;
}
 [2003-02-14 09:07 UTC] alex dot madon at bestlinuxjobs dot com
Hi Iliia,

Marc sent me a patch that solved the problem.
 [2003-02-14 09:16 UTC] mboeren@php.net
The same error would have occurrred in the latest version too. The patch I sent solves the problem, and should have no side-effects. I would like to run the dbx-tests before I commit the patch to cvs though.

 [2003-02-14 09:47 UTC] alex dot madon at bestlinuxjobs dot com
Marc:
I am trying to run the tests (compile the cgi version).
I'll tell you the results of the tests if any.
Alex
 [2003-02-19 07:33 UTC] mboeren@php.net
Fixed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Nov 27 02:01:38 2024 UTC