Re: Problems with multiple query
| From: | Nuno Silva | Date: | Sun, 18 Mar 2001 17:15:04 +0000 |
| Subject: | Re: Problems with multiple query | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-44452@lists.php.net to get a copy of this message | ||
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