View Single Post

  #3 (permalink)  
Old 03-15-2007
Jerry Stuckle
 
Posts: n/a
Default Re: Table remains locked after exiting script

Taras_96 wrote:
> Hi all,
>
> I've been told that when a PHP script exits, then all tables that were
> locked from within the PHP script are unlocked.. obviously this is a
> good idea.
>
> However, I'm experiencing a problem in the website that I'm currently
> coding; the table doesn't unlock after I exit the script. Below is the
> PHP snippet relating to the problem area.
>
> $com->setQuery('LOCK TABLE updates WRITE, documents WRITE');
> $com->execute();
> $com->reset();
>
> exit();
>
> $com is a reference to an object that we use to build up and execute
> queries, and I don't think is that important as it doesn't do anything
> special (it's essentially an extra layer we've added to ensure that
> any strings that are used in the query are properly escaped).
>
> The user that is used in executing this query is called
> 'lockedDocManip'. When the Server connections are viewed in MySQL
> Admin, this user has a connection after exit() is called because
> persistent connections are being used. After running the PHP script
> above, I've clicked the 'home' link, which uses SQL to check that the
> user is currently logged in (an SQL user called 'login').
>
> This new connection that is established is in a 'locked' state when
> viewed in Mysql Admin, which confirms that the tables are still
> locked.
>
> What could be causing this problem?
>
> The reason why I'm using locks is that a field exists that multiple
> users can edit, but it can not be re-edited once it has been edited
> once. I thus lock the tables, see if anyone has edited the field, and
> if not, edit it. If I don't lock the tables a race condition occurs.
> Is there perhaps an alternative solution to this problem?
>
> Thanks
>
> Taras
>


Why in the world would you use persistent connections?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Reply With Quote