473,403 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

deleting a mysql record in active result

Hello,

I'm doing a select in wich I retrieve some values.

If the value is in an array, I must delete the record.

As I'm doing a "mysql_fetch_object", may I delete this record inside the
loop ?

when doing a mysql_query, do I have a "local" copy or just a link to the
mysql query result. In the first case I may delete the record as I get an
"image" of the query result, in the second case I shouldn't as the query
result will be changed by the deletion of any record.

Bob

Apr 12 '06 #1
5 1389
Bob Bedford wrote:
Hello,

I'm doing a select in wich I retrieve some values.

If the value is in an array, I must delete the record.

As I'm doing a "mysql_fetch_object", may I delete this record inside the
loop ?

when doing a mysql_query, do I have a "local" copy or just a link to the
mysql query result. In the first case I may delete the record as I get an
"image" of the query result, in the second case I shouldn't as the query
result will be changed by the deletion of any record.

Bob


Bob,

I'm not sure whether you can do it safely or not - I've never tried.

What I do is something I learned many, many moons ago when I was working on a
mainframe database (DB2). When I want to delete a row, I will save it's id in
an array. Then after I'm done with the result set, I go back and build a delete
command to get rid of all of them at one time. Or, you could issue several
delete commands to get rid of them individually.

It solves any potential problems which might result, especially if you change
databases (not likely - but who knows?).
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Apr 12 '06 #2
I always thought this was ok. It seems simple enough to test, but I
think reasoning can sort this out.

User A and B make same query at same time.

Query is 'select * from big_table limit 10';

Results are printed out for user A but user B deletes in of the 10 A
recieved whilst being called.

If the delete counts A no longer has 10 records, unless the sql is run
again. But then other changes could have happened, and the process
could repeat indefinately.

I'd say it would be as safe as houses. The only danger is you use the
same query resource and lose the loop, which is not a db issue but a
programming one.

Apr 13 '06 #3
fletch wrote:
I always thought this was ok. It seems simple enough to test, but I
think reasoning can sort this out.

User A and B make same query at same time.

Query is 'select * from big_table limit 10';

Results are printed out for user A but user B deletes in of the 10 A
recieved whilst being called.

If the delete counts A no longer has 10 records, unless the sql is run
again. But then other changes could have happened, and the process
could repeat indefinately.

I'd say it would be as safe as houses. The only danger is you use the
same query resource and lose the loop, which is not a db issue but a
programming one.


Fletch,

A completely different scenario. If A is holding locks on the rows, B will not
be able to delete them. However, as owner of the locks, A would still be able
to delete the rows.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Apr 13 '06 #4
Hmmn. I'd not really thought of that. How to distinguish a from b
though? not db login, as user a and b are effectively the same program
run by a web server.

Apr 13 '06 #5
fletch wrote:
Hmmn. I'd not really thought of that. How to distinguish a from b
though? not db login, as user a and b are effectively the same program
run by a web server.


They'll be using different connections.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Apr 13 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Rob | last post by:
Thanks for the Help on the other problems...all resolved. One last (hopefullly) problem I can't seem to get around for this program...why isn't this deleting the row i want? It does nothing. Now...
3
by: Nathan Bloom | last post by:
Hi, I have a data entry form (access 2000) that also allows the user to add, update, and delete records from the form. The Delete action is carried out in an event procedure and has the...
46
by: DP | last post by:
hi, i've got a form, with a subform in it. i've got a delete button in the subform. the code i;ve got is; Private Sub cmdDeleteRecord_Click() msg = "Are you sure you want to delete this...
5
by: Manish | last post by:
The topic is related to MySQL database. Suppose a table "address" contains the following records ------------------------------------------------------- | name | address | phone |...
110
by: alf | last post by:
Hi, is it possible that due to OS crash or mysql itself crash or some e.g. SCSI failure to lose all the data stored in the table (let's say million of 1KB rows). In other words what is the worst...
1
by: webandwe | last post by:
Hi The code below I took from a postgre file and convert it with a program to a mysql. Once i tried to import it to mysql it gave me an error and when i past in a php file to upload it trough a...
0
Coldfire
by: Coldfire | last post by:
Since i cannot show the differences in a two-column like table. I am first putting MS SQL Server 2005 and then MySQL 5.x. MS SQL Server 2005 Brief Overview - SQL Server is a full-fledged...
6
by: keeps21 | last post by:
I'm having a bit of trouble creating a page to delete a story from the content table in my database. I have checked my DELETE query directly in phpmyadmin and it is working fine. I am echoing...
2
osward
by: osward | last post by:
Hello there, I am using phpnuke 8.0 to build my website, knowing little on php programing. I am assembling a module for my member which is basically cut and paste existing code section of...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.