Jump to content

Recommended Posts

I am having trouble understanding how to use LOCK TABLE.

I need to prevent inserts to a table while a PHP script is using it.

Is LOCK TABLE the right way to do this, or am I better off using my own method, such as a "lockfile"?

I really only need to prevent another user running the PHP script and altering the table while script is already running.

Link to comment
https://forums.phpfreaks.com/topic/71412-solved-lock-table-to-prevent-insert/
Share on other sites

The PHP script will aquire info from text files, then insert the info into the a table.

It will then get info from more text files and insert into the table acording to the info from the first insert, so to match the individual records. It will then select all the data in the table, process and display it.

Oh, first it needs to delete all records from the table, so it is starting new. The table is only used for temp storage.

This is nearly the same method I've used in the past for similar tasks.

 

The source is up to 2,000 text files, containing up to 50 records each.

 

Problem: A user starts the script, a second user starts the script before the first has finished. The second instance will delete all entries made by the first, attempting to clear it for itself, then both instances will be inserting records into it.

 

With the amount and complexitity of the info, combined with it needing to be processed 2 or 3 times over, I don't see anyway to do it without using a table to hold the info.

After the script is done and the info displayed, the table is no longer needed.

 

Hopefully this makes some sence. The way I see it, "while the script is running" would be the time between it starting and ending.

Oh, first it needs to delete all records from the table, so it is starting new. The table is only used for temp storage.

 

Problem: A user starts the script, a second user starts the script before the first has finished. The second instance will delete all entries made by the first, attempting to clear it for itself, then both instances will be inserting records into it.

 

After the script is done and the info displayed, the table is no longer needed.

So why not use temporary tables, one for each instantiation of the script?

Yea, I just had that suggested from elsewhere too.

I guess I would give a "CREATE TABLE ..." query using mysql_query(), then drop the table afterwards?

My best guess is to use a microtime stamp in the name, to make it unique.

 

Thanks for the info.

Yea, I just had that suggested from elsewhere too.

I guess I would give a "CREATE TABLE ..." query using mysql_query(), then drop the table afterwards?

My best guess is to use a microtime stamp in the name, to make it unique.

 

Thanks for the info.

No, a "true" TEMPORARY table type, that resides in memory, not on disk.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.