Re: Problems with multiple query

From: Date: Mon, 19 Mar 2001 07:56:42 +0000
Subject: Re: Problems with multiple query
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-44498@lists.php.net to get a copy of this message
Thanks; in fact I've tryed the second solution and it works for me; but I can't understand why the script stop working during the upgrade of system. The most strange thing is that, after a deeper investigation on the code, I've found the PHP engine does something like closing the connection after the second pg_exec command. In fact, by using persistent connections I've partially corrected the problem and the codes doesn't complain about using an invalid (but not null) connection descriptor; but it stills be unable to get results from successive queries, also if result index are valid ! This sounds very strange for me. Thank you for your help ! Luca Lazzeroni "Nuno Silva" <nuno_silva@websolut.net> ha scritto nel messaggio news:3AB4ED18.80603@websolut.net... > Hello, > > if the second query loops inside a _for_ statement and needs values from > the first query you have two options: > > 1. save all the results from query one to some array and then loop > inside the array within the _for_ statement executing new sql; > 2. open two separate connections to the database and work with the two. > like this: > $conn1 = pg_connect(...); > $conn2 = pg_connect(...); > ... > qry1 = pg_exec($conn1, $sql1); > ... > for ($i=.....) { > ... > $qry2 = pg_exec($conn2, $sql2); > ... > } > > Hope this helps, > Nuno Silva > > > Luca Lazzeroni wrote: > > > Hi, > > I've recently migrated a system with PHP 4.0.3pl1 and PostgreSQL 7.0.2 - > > RedHat Linux 5.1 (yes 5) to a new one with PHP 4.0.4pl1 - PostgreSQL 7.0.2 - > > RedHat Linux 7.0. > > > > All my database applications work fine except one which does strange things: > > this is a piece of code: > > > > ----8<------- CUT ---- > > > > $conn = pg_connect("dbname=aaaa user=yyyyy password=xxxxxx"); > > > > $sql = "select * from table_a where condition_a"; > > $qry1 = pg_exec ($conn,$sql); > > > > $obj1 = pg_fetchobject($qry1,0); > > > > // Until here everything works fine > > > > $sql2 = "select * from table_b where condition_b=".$obj1->value_a; > > $qry2 = pg_exec ($conn,$sql2); > > > > ----8<------- CUT ---- > > > > The second query is nested in a for-loop running for every object in the > > first query; for performance reason I need to maintain the two queries > > independent. > > > > After executing (correctly) the first one, the system starts doing strange > > things with the second one: > > > > Warning: Unable to jump to row 0 on PostgreSQL result index 23 in cerca.php3 > > on line 467 > > > > and it fails to read data. > > The strange thing is that the system does the same things for EVERY database > > where I must use two consecutive queries ! > > > > Is there anyone who can help me ? > > > > Thanks in advance > > > > Luca Lazzeroni > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#44498) next »