You are here: Re: resultsets - deleting from while processing safe? « PHP Programming Language « IT news, forums, messages
Re: resultsets - deleting from while processing safe?

Posted by Jim Michaels on 03/19/06 07:18

"Chung Leong" <chernyshevsky@hotmail.com> wrote in message
news:1142704883.623831.317580@z34g2000cwc.googlegroups.com...
>
> Jim Michaels wrote:
>> Is it safe to do what is below? deleting from a resultset while you are
>> processing it? I don't know how dynamic the SQL database is. I assume
>> you
>> get a cursor to live dataset. Even if it is a cursor as opposed to a
>> table,
>> will the cursor's integrity be ruined if the current record is deleted?
>>
>> $q2=mysql_query("SELECT * FROM table1 WHERE id1=5", $link);
>> while ($row2=mysql_fetch_array($q2)) {
>> //do some stuff with resultset
>> mysql_query("DELETE FROM table1 WHERE id1=5 AND id2=$row2[id2]",
>> $link);
>> }
>> mysql_free_result($q2);
>
> With MySQL I believe it's safe, as the client buffers the whole result
> set. It's more efficient though to save the ids into an array, then
> delete all the applicable rows in a single operation with a "id2 IN (
> ... )" condition.
>

thx for the tip. Hadn't thought of that. Makes sense.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация