Re: Problems with multiple query
| From: | Nuno Silva | Date: | Mon, 19 Mar 2001 13:30:35 +0000 |
| Subject: | Re: Problems with multiple query | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-44589@lists.php.net to get a copy of this message | ||
Hi,
please note: You can *not* fetch results that require earlier results using the pg_* functions. Explaination: when you submit a query the php script doesn't know about the content of all rows returned, instead the interface API makes use of pointers to fetch only the requested rows from the result.
That said, if you make a second call to pg_exec() consider saving all the results somewhere else if you need the previous set of results.
Regards,
Nuno Silva
Luca Lazzeroni wrote:
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:7.0.2 -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 - PostgreSQLthings:RedHat Linux 7.0. All my database applications work fine except one which does strangestrangethis 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 doingcerca.php3things with the second one: Warning: Unable to jump to row 0 on PostgreSQL result index 23 indatabaseon line 467 and it fails to read data. The strange thing is that the system does the same things for EVERYwhere 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