[PHP-DB] SELECT FOR UPDATE

2008-06-02 Thread Philip Thompson

Hi all.

Which is more efficient in order to use SELECT FOR UPDATE?

% SELECT * FROM `table` WHERE (`table_id` = 32) LIMIT 1 FOR UPDATE;
% UPDATE `table` SET `field_name` = 'Pizza' WHERE (`table_id` = 32)  
LIMIT 1;


OR

% SELECT `field_name` FROM `table` WHERE (`table_id` = 32) LIMIT 1  
FOR UPDATE;
% UPDATE `table` SET `field_name` = 'Pizza' WHERE (`table_id` = 32)  
LIMIT 1;



Note: the 2nd query in each is the same. Is there any difference in  
using * and specifying the actual field you want to update? It seems  
like there would be very little difference because this is causing a  
row-lock - all the data in that row is not-updatable anyway.


I'm adding transactions and row-locking into my application. If I can  
just use the first method (because it's easier to specify '*' instead  
of every column I want to update), then I'd like to. Any thoughts are  
welcome!


Thanks in advance,

~Philip


Personally, most of my web applications do not have to factor 13.7  
billion years of space drift in to the calculations, so PHP's rand  
function has been great for me... ~S. Johnson


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] select and update together

2002-01-21 Thread James Kupernik

Is it possible to select 10 records that have a NULL field and update that
field to become Y instead of NULL? If so what would this syntax be?

This is what I have now

$result = mysql_query(SELECT * FROM catalogs WHERE PROCESSED IS NULL LIMIT
$i,10);

I want to add an UPdate to it, but not sure it's possible.

Thanks for any advice you can provide.

James



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP-DB] select and update together

2002-01-21 Thread Robert V. Zwink

http://www.mysql.com/doc/U/P/UPDATE.html

UPDATE catalogs SET PROCESSED = Y WHERE PROCESSED IS NULL LIMIT $i,10

Is this what you are looking for?

Robert V. Zwink
http://www.zwink.net/daid.php

-Original Message-
From: James Kupernik [mailto:[EMAIL PROTECTED]]
Sent: Monday, January 21, 2002 10:56 AM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] select and update together


Is it possible to select 10 records that have a NULL field and update that
field to become Y instead of NULL? If so what would this syntax be?

This is what I have now

$result = mysql_query(SELECT * FROM catalogs WHERE PROCESSED IS NULL LIMIT
$i,10);

I want to add an UPdate to it, but not sure it's possible.

Thanks for any advice you can provide.

James



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]