ID: 16295
Updated by: [EMAIL PROTECTED]
Reported By: [EMAIL PROTECTED]
-Status: Open
+Status: Bogus
Bug Type: MySQL related
Operating System: MDK 8.2
PHP Version: 4.1.2
New Comment:
This is not a bug. You should open two separate connections
to the database and use the link identifier in mysql_query().
Also, this is not very efficient. It would be better to
first fetch the whole array containing the id's and then
make a comma separated list of them and use 'IN()' function
in the query.
ie. "DELETE FROM tbl2 WHERE id IN($list_of_ids)"
Previous Comments:
------------------------------------------------------------------------
[2002-03-27 10:53:28] [EMAIL PROTECTED]
I more specify my problem:
There are two identical blocks like this
1| $sql=mysql_query("SELECT id FROM tbl");
2| while($row = mysql_fetch_array($sql, MYSQL_ASSOC)) {
3| mysql_query("DELETE FROM tbl2 WHERE
4| id=".$row["id"]);
5| }
8| $sql=mysql_query("SELECT id FROM tbl");
9| while($row = mysql_fetch_array($sql, MYSQL_ASSOC)) {
10| mysql_query("DELETE FROM tbl2 WHERE
11| id=".$row["id"]);
12| }
fetching array on line 8 writes "# is not a valid mysql result
resource"
But when I put whatever query between these blocks, invalid resource
from the second block disappears and the query works good as well.
It looks like I can't use DELETE query when selecting
So, this is ok:
1| $sql=mysql_query("SELECT id FROM tbl");
2| while($row = mysql_fetch_array($sql, MYSQL_ASSOC)) {
3| mysql_query("DELETE FROM tbl2 WHERE
4| id=".$row["id"]);
5| }
6| $sql=mysql_query("SELECT id FROM tbl"); //this does nothing but
prevent error from next block
7| $row = mysql_fetch_array($sql, MYSQL_ASSOC);
8| $sql=mysql_query("SELECT id FROM tbl");
8| while($row = mysql_fetch_array($sql, MYSQL_ASSOC)) {
9| mysql_unbuffered_query("DELETE FROM tbl2 WHERE
10| id=".$row["id"]);
11| }
------------------------------------------------------------------------
[2002-03-27 10:53:08] [EMAIL PROTECTED]
I don't think this is a PHP problem. Try this:
Modify your script so that it looks like:
1| $sql=mysql_query("SELECT id FROM tbl");
2| while($row = mysql_fetch_array($sql, MYSQL_ASSOC)) {
3| mysql_unbuffered_query("DELETE FROM tbl2 WHERE
4| id=\"".$row["id"]."\"");
5| }
If this works, change this bug to bogus.
------------------------------------------------------------------------
[2002-03-27 09:30:40] [EMAIL PROTECTED]
I try to put mysql_query everywhere (there are no
mysql_unbuffered_queryies)
Still the same.
What's important? mysql_errno is always null and the error occures in
various resources.
Result of faulty operation in a database is sometimes ok and sometimes
not.
------------------------------------------------------------------------
[2002-03-27 06:16:04] [EMAIL PROTECTED]
Don't mix mysql_unbuffered_query and mysql_query.
mysql_unbuffered_query is for fetching rows in SELECT,
SHOW or DESCRIBE statements without buffering it.
Use mysql_query ("DELETE ... instead.
------------------------------------------------------------------------
[2002-03-27 06:15:58] [EMAIL PROTECTED]
Don't use mysql_unbuffered_query and mysql_query mixed.
mysql_unbuffered_query is for fetching rows in SELECT,
SHOW or DESCRIBE statements without buffering it.
Use mysql_query ("DELETE ... instead.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/16295
--
Edit this bug report at http://bugs.php.net/?id=16295&edit=1