MySQL Forums
Forum List  »  PHP

PHP transaction issue ( using 'for update')
Posted by: Mark Procter
Date: April 04, 2006 07:48PM

Hi I've got a bit of a problem trying to get the functionality I want working with my university project.

I've created a 'records update' page where the variables are selected within a transaction, like this:

mysql_query("begin");

$sql = "SELECT * FROM animal WHERE animal_id = '$thisAnimal_id' for update";

$result = MYSQL_QUERY($sql);
$numberOfRows = MYSQL_NUMROWS($result);
if ($numberOfRows==0) {
?>
...ect

(NB The 'commit' is not done on this page but on the post-to page of the form on this page.)

I want to create this scenario: when a user has selected this animal for update and is in the process of changing variables in the form, another user cannot select the same animal. I thought this was possible with the 'for update' clause of the select request but it seems that other users are still able to select the same animal and get all the variables from the db??

I know that its not logical to have the commit on the post page but seen as its all part of the same transaction i don't see why this isn't possible.

Please can someone shed some light on my error?

Thanks in advance.

PS. I'm using mysql5 and innodb tables btw! I know that transactions work where the begin and commit are on the same page but I can't see a way of doing that in this case.

Options: ReplyQuote


Subject
Written By
Posted
PHP transaction issue ( using 'for update')
April 04, 2006 07:48PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.