Many PHP errors in AlertProfiles under PHP5

Bug #258311 reported by Morten Brekkevold
2
Affects Status Importance Assigned to Milestone
Network Administration Visualized
Fix Released
Medium
Magnus Eide

Bug Description

AlertProfiles running under PHP5 produces many ill-sounding error messages,
all displayed in big, flashy, yellow boxes.

Most of these seem to be related to PostgreSQL database calls. Although
they seem to indicate problems with storing changes in the database,
changes actually seem to be stored properly, as before under PHP4.

One of the original AlertProfiles authors has commented that many of these
errors have probably always been there, it's just that PHP5 has become more
strict about reporting them.

We've received a patch to quench the error messages, but we should fix the
actualt errors, not remove the symptoms. The fixes should remain
compatible with PHP4, if at all possible.

I will add more info about the error messages themselves in the comments.

[http://sourceforge.net/tracker/index.php?func=detail&aid=1991654&group_id=107608&atid=648170]

Revision history for this message
Morten Brekkevold (mbrekkevold) wrote :

Originator: YES

When opening the alertprofiles page, not yet having created a default
profile, I receive a great big bunch of these error messages at the bottom
of the page:
---
AlertProfiles PHP Errorhandler

AlertProfiles error-handler:Unkown error type: [2]
pg_query_params() [function.pg-query-params]: No array passed

/usr/local/nav/apache/webroot/alertprofiles/databaseHandler.php
on line [1477]
---

I also get some of these:
---
AlertProfiles PHP Errorhandler

AlertProfiles error-handler:Unkown error type: [2]
pg_fetch_array() [function.pg-fetch-array]: Unable to jump to row 24 on
PostgreSQL result index 77

/usr/local/nav/apache/webroot/alertprofiles/databaseHandler.php
on line [947]
---

Revision history for this message
Morten Brekkevold (mbrekkevold) wrote :

Originator: YES

please ignore my previous comment. I was testing on the dev server, and
m-eide was apparently already in the process of making some changes, which
caused these error messages. Will re-test on a production server.

Revision history for this message
Morten Brekkevold (mbrekkevold) wrote :

Originator: YES

Helder Vieira Mendes reported these errors on the nav-users mailing list:

«I have installed NAV 3.3.3 in Debian but the "Alert Profiles" return the
two
folowing errors when I try to "Edit alert service rules for a time
period"»

#########################################
AlertProfiles PHP Errorhandler
error
AlertProfiles error-handler:Unkown error type: [2]
pg_fetch_row() expects parameter 1 to be resource, boolean given

/var/www/nav/alertprofiles/databaseHandler.php
on line [1969]
##########################################

############################################
AlertProfiles PHP Errorhandler
error

AlertProfiles error-handler:Unkown error type: [2]
pg_exec() [function.pg-exec]: Query failed: ERROR: syntax error at end of

input
at character 40

/var/www/nav/alertprofiles/databaseHandler.php
on line [1968]
################################################

Revision history for this message
Morten Brekkevold (mbrekkevold) wrote :

Originator: YES

In december, Keith Latta also reported the following errors, which he
claims came while using PHP4. He says the appeared when he was "creating a
new user"; I don't know what he means with this statement, since there is
no such thing as "creating users" in AlertProfiles. He never responded to
this, but nevertheless, here are the error messages:

####################
AlertProfiles error-handler:Unkown error type: [2]

pg_fetch_row(): supplied argument is not a valid PostgreSQL result
resource

/var/www/nav/alertprofiles/databaseHandler.php
on line [1994]
####################

####################
AlertProfiles error-handler:Unkown error type: [2]

pg_exec() [function.pg-exec<http://nav/alertprofiles/function.pg-exec>]:
Query
failed: ERROR: syntax error at end of input at character 41

/var/www/nav/alertprofiles/databaseHandler.php
on line [1993]
####################

Revision history for this message
Magnus Eide (m-eide) wrote :

Originator: NO

#########################################
AlertProfiles PHP Errorhandler
error
AlertProfiles error-handler:Unkown error type: [2]
pg_fetch_row() expects parameter 1 to be resource, boolean given

/var/www/nav/alertprofiles/databaseHandler.php
on line [1969]
##########################################

############################################
AlertProfiles PHP Errorhandler
error

AlertProfiles error-handler:Unkown error type: [2]
pg_exec() [function.pg-exec]: Query failed: ERROR: syntax error at end of

input
at character 40

/var/www/nav/alertprofiles/databaseHandler.php
on line [1968]
################################################

####################
AlertProfiles error-handler:Unkown error type: [2]

pg_fetch_row(): supplied argument is not a valid PostgreSQL result
resource

/var/www/nav/alertprofiles/databaseHandler.php
on line [1994]
####################

####################
AlertProfiles error-handler:Unkown error type: [2]

pg_exec() [function.pg-exec<http://nav/alertprofiles/function.pg-exec>]:
Query
failed: ERROR: syntax error at end of input at character 41

/var/www/nav/alertprofiles/databaseHandler.php
on line [1993]
####################

All these are related to Postgres version, not PHP version.

Quoting http://php.net/pg-last-oid:
> OID field became an optional field from PostgreSQL 7.2 and will not be
present by default in PostgreSQL 8.1.

So when Alert Profiles were made they choose to get the id of the newly
inserted row back by using pg_getlastoid() to retrieve the OID and then
selecting the id of the row associated with that OID, which might not work
in Postgres >= 8.1

In my branch I have replaced pg_getlastoid() with a query for "SELECT
currval('nameofsequence') AS lastid" which will return the correct id of
the last inserted row. This offcourse may not work either, as the naming
convetion of sequences has also changed.

Revision history for this message
Magnus Eide (m-eide) wrote :

Originator: NO

The PostgreSQL library in PHP recieved a lot of changes from PHP 4 to PHP
5, new functions were added, and some of the old ones were renamed, an
example is pg_num_rows() which were called pg_numrows() in PHP 4. This
produced a lot of errors when running AlertProfiles on PHP 5. Another
source for errors were also PostgreSQL itself, where it seems that the way
you work with sequences have changed (fetching the last id from a sequence
were done in a different way in Postgres < 8).

For 3.4.x AlertProfiles now uses the PHP 5 PostgreSQL functions by
default, and retains PHP 4 support by using function_exists() and defining
the functions if function_exists() returns false (which will happen if we
are running PHP 4). These function declarations can be found in the file
php4support.php.

The queries to PostgreSQL sequences are also changed so that they work
with Postgres >= 8 (it will probably not work with Postgres < 8).

Put all this together and AlertProfiles works on both PHP 4 and PHP 5.

Revision history for this message
Morten Brekkevold (mbrekkevold) wrote :

Originator: YES

Magnus' bugfix-branch has been merged with series/3.4.x and will be pushed
to metanav soon, in time for NAV 3.4.1.

Changed in nav:
milestone: v3.4 → v3.4.1
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.