Re: [INTERFACES] Duplicate INSERTS into pgsql table via PHP

From: Jason Earl <jearl(at)box100(dot)com>
To: David Osborne <David(dot)Osborne(at)nottingham(dot)ac(dot)uk>
Cc: pgsql-interfaces(at)postgreSQL(dot)org
Subject: Re: [INTERFACES] Duplicate INSERTS into pgsql table via PHP
Date: 1999-12-13 20:06:26
Message-ID: 385551C2.791CCA4F@box100.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

I am running a very similiar setup (modified RedHat 5.2, Apache 1.3.9,
PHP 3.0.12, PostgreSQL 6.5.2) and I cut and pasted your example into
tester.php3 and created a database cczdao and a table mytest as:

create table mytest(foo int, bar text);

And it worked just fine. Perhaps there is something else that is going
wrong? Could you perhaps give a little more info. Are there any
redirects happening, does the same script generate the form and insert
the data into the table? Also, I am curious as to why you are not using
the nifty persistent connection pg_pconnect function?

Jason Earl

David Osborne wrote:
>
> 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/
>
> ************

In response to

Browse pgsql-interfaces by date

  From Date Subject
Next Message Craig Orsinger 1999-12-13 20:52:20 Re: [INTERFACES] ESQL/C Docs: Request for code
Previous Message Ed Loehr 1999-12-13 20:04:54 Re: [GENERAL] Is it safe to INSERT/DELETE during VACUUM?