|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-03-26 18:38 UTC] joyeux at 1984 dot cz
This SOMETIMES produces the error
"3 is not a valid mysql resource on line 2"
(or other numbers)
First fetch_array is usually good. It looks like php forgot a resource link when calling other query.
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| }
When I use an array to store data from tbl1 instead direct fetching, it works.
1| $ARR=array();
2| $sql=mysql_query("SELECT id FROM tbl");
3| while($row=mysql_fetch_array($sql, MYSQL_ASSOC)) $ARR[]=$row;
4| foreach($ARR as $row) mysql_unbuffered_query("DELETE FROM tbl2 WHERE id=".$row["id"]);
I can't find where is the problem. I try to put some sleep() after mysql_query but it's the same.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 19:00:01 2025 UTC |
This SOMETIMES produces an error "3 is not a valid mysql resource on line 2" (or other error numbers) First fetch_array is usually good. It looks like php forget a resource link when calling other query (line 3). 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 id=".$row["id"]); 5| } When I first fetch all data to an array and then use them by the same way, it works. 1| $ARR=array(); 2| $sql=mysql_query("SELECT id FROM tbl"); 3| while($row=mysql_fetch_array($sql, MYSQL_ASSOC)) $ARR[]=$row; 4| foreach($ARR as $row) mysql_unbuffered_query("DELETE FROM tbl2 WHERE id=".$row["id"]); I can't find where is the problem. I try to put some sleep() after queries but nothing happens.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.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.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.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| }