Duplicate INSERTS into pgsql table via PHP

From: David Osborne <David(dot)Osborne(at)nottingham(dot)ac(dot)uk>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: Duplicate INSERTS into pgsql table via PHP
Date: 1999-12-13 10:10:51
Message-ID: 1301.945079851@unix.ccc.nottingham.ac.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

I asked about this on the PHP list but no-one seemed to know what could be causing the problem.

I'm setting up a Web-enabled database using PostgreSQL 6.5.3 and
communicating with it via PHP 3.0.12 as an Apache module for Apache
1.3.9, all running on a Mandrake Linux 6.1 system.

Any PHP page that reads from a Postgres table works fine, as does any
table manipulation using the psql terminal monitor. But the big problem
is if I use a PHP page that does an INSERT on a table, the table ends up
with two rows being inserted instead of one.

For example, for a table with columns of an int and varchar, the code

$conn = pg_connect("", "", "", "","cczdao");
$result = pg_exec($conn, "insert into mytest values (333, 'some text')");
pg_close($conn);

causes two rows, each with values 333 and 'some text' to be inserted.
For PHP code inserting values where the int value is defined as
max(intcolumn)+1, or where the table's int column is allowed to use its
default of the nextval of some sequence, the inserted rows have
consecutive values in that column.

Running the Postgres "postmaster" process in debug mode shows two
separate backends being started up, with consecutive pid's, each one
doing an INSERT. I found from my Apache access log that these are due to
two consecutive requests for the same page, when using Netscape (4.7 on
Linux, 4.5 on Solaris). Yet this does NOT happen using Lynx, which
produces one request for the page and hence only results in one record
being inserted.

Checking further shows that even a page which only calls pg_exec to do a
SELECT from the table gets requested twice by Netscape, but only once by
Lynx. Any other PHP pages, such as one which only calls phpinfo(), are
requested once by both Netscape and Lynx. So it's only the pages which
are accessing Postgres which provoke two consecutive requests, as logged
by Apache, when requested by Netscape (and if those pages are running an
INSERT query, result in two records being inserted into the table).

I've got Netscape set to not use proxies (direct connection to
Internet), in case our usual proxy autoconfig script got in the way;
also, it makes no difference whether I allow local disk or memory
caching, nor whether the document freshness is checked every time, once/
session or never.

Has anyone got any suggestions? I'm running out of ideas of what to try
next.

thanks
--
David Osborne david(dot)osborne(at)nottingham(dot)ac(dot)uk
Academic Computing Services phone/voicemail: +44 (0)115 951 3397
The University of Nottingham fax: +44 (0)115 951 3358
Nottingham NG7 2RD, UK http://www.nottingham.ac.uk/~cczdao/

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Michael Meskes 1999-12-13 10:53:32 pgaccess question
Previous Message Michael Meskes 1999-12-13 09:46:35 Re: [INTERFACES] libpq linking problem