RobertSubnet Posted February 10, 2013 Share Posted February 10, 2013 Hello all. I am attempting to use PHP to lock a MySQL table that uses a myisam engine. The code I am using is as follows: mysql_query("LOCK TABLES stuff4sale WRITE;"); But when executing a show open tables from the command line I see that the table does not get locked. I can lock and unlock the table just fine from the command line but not when using PHP. This should be pretty simple but obviously I am missing something. Prior to running the PHP I have confirmed a working connection to the database. What am I missing? Thank you for your time and comments. Quote Link to comment Share on other sites More sharing options...
RobertSubnet Posted February 12, 2013 Author Share Posted February 12, 2013 I think I have finally found the answer: skip_locking or in this case skip_external_locking is set to on. Now I am trying to figure out how to enable external locking; my my.cnf file has the following: [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql enable-locking external-locking Save and restart the mysqld service and skip_external_locking is still set to on. Any ideas on why the my.cnf is not turning off the skip_external_locking? Thanks. Quote Link to comment Share on other sites More sharing options...
kicken Posted February 12, 2013 Share Posted February 12, 2013 Are you delaying your script after issuing the lock? If not, once the script ends your connection to mysql will close and the lock will probably be released. Quote Link to comment Share on other sites More sharing options...
RobertSubnet Posted February 12, 2013 Author Share Posted February 12, 2013 Kicken I had not considered that. I am just running the script and then checking on a command line to see if the table is locked with a show open tables. Is there someway to confirm that the table was locked when the script ran? Thanks. Quote Link to comment Share on other sites More sharing options...
fenway Posted February 12, 2013 Share Posted February 12, 2013 Use "SHOW OPEN TABLES" within the session. Quote Link to comment Share on other sites More sharing options...
RobertSubnet Posted February 13, 2013 Author Share Posted February 13, 2013 Well I am not sure how to display the output from show open tables using PHP but I did use a sleep() just after locking the tables from PHP. Checking the command line and sure enough the table was locked. So Kicken it looks like you were correct once the script ended the lock released. Thank you all for your help!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.