[nycphp-talk] mysql concurrency redux
felix zaslavskiy
felix at students.poly.edu
Mon Feb 23 04:31:23 EST 2004
Should not you be doing update of lastmod at the same time you update
string ? I think you may have a logical error that is why your script
does not work.
>
> Here's the experiment. When I load a copy into each of two windows and
> submit both so they overlap in time, I expect the first to succeed and
> the second to abort. Is there something stupid I'm doing wrong here?
> (btw I am making sure to submit something in the 'string' field that's
> different from what's in the db to ensure that my timestamp updates)
>
> <?php
>
> require('DB.php');
> $db=DB::connect('mysql://joe_user@localhost/test');
> $db->setFetchMode(DB_FETCHMODE_ASSOC);
>
> if($_SERVER['REQUEST_METHOD']=='POST') {
>
> $db->query("set transaction isolation level READ
> UNCOMMITTED");$db->query("start transaction");
> // compare our timestamp with db
> $theirs = $db->getOne("select lastmod from test01 where
> id=1"); echo "sleeping..."; flush();
> sleep(4);
> if ($theirs != $_POST['lastmod']) {
> echo "record has been modified by someone else.
> reloading...";
> $db->query("rollback");
> } else {
> $db->query('update test01 set string =' .
> $db->quote($_POST['string']) . ' where id=1');
> $db->query("commit");
> echo "ok, $theirs = {$_POST['lastmod']}, updating...
> ";
> }
> }
> $formData = $db->getRow("select * from test01 where id = 1");
> ?>
>
> <form action="<?=$_SERVER['PHP_SELF']?>" method="POST">
> Id <input type="text" size="2" name="id"
> value="<?=$formData['id']?>" /><br />
> Last Mod <input type="text" size="24" name="lastmod"
> value="<?=$formData['lastmod']?>" /><br />
> String <input type="text" size="30" name="string"
> value="<?=htmlspecialchars($formData['string'])?>" /><br />
> <input type="submit" />
> </form>
>
> FWIW I've tried this with both 4.0.13-standard and 4.0.16-max-nt-log,
> both with PEAR DB 1.6.0RC6
>
>
> Many many thanks,
>
>
> ---
> David Mintz
> http://davidmintz.org/
>
> "Anybody else got a problem with Webistics?" -- Sopranos 24:17
> _______________________________________________
> talk mailing list
> talk at lists.nyphp.org
> http://lists.nyphp.org/mailman/listinfo/talk
>
More information about the talk
mailing list