Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7818089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:27:31+00:00 2026-06-02T06:27:31+00:00

The function has next structure: $q = ‘LOCK TABLES table1 WRITE;’; mysql_query($q); $q =

  • 0

The function has next structure:

$q = 'LOCK TABLES table1 WRITE;';
mysql_query($q);    
$q = 'select id from table1 where is_delete = 0 limit 1;';
$res = mysql_fetch_assoc(mysql_query($q));
if($res) {
$q = 'UPDATE table1 SET is_delete = 1 WHERE id = '".$res['id']."'';
mysql_query($q);
}
$q = 'UNLOCK TABLES;';
mysql_query($q);

I locking all tables, but queries run parallel.
How fix this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T06:27:33+00:00Added an answer on June 2, 2026 at 6:27 am

    Check whether you’re getting any MySQL errors on the LOCK TABLES query:

    $q = 'LOCK TABLES table1 WRITE';
    $r = mysql_query($q) or die(mysql_error());    
    

    However, if this is all you are doing, you can also simply write:

    UPDATE `table1 SET `is_delete` = 1 WHERE `is_delete` = 0 LIMIT 1
    

    which does not require any locks at all. Of course, this will only work if the data from your first query is not being processed in any way, and if it doesn’t really matter which row you are updating, as long as it’s one in which is_delete is set to 0. This is what the code you posted does, too, but it’s not immediately obvious to me what you would want to use this code for 🙂

    More generally, if you are using the default InnoDB storage engine for your MySQL table, you may want to look into SELECT … FOR UPDATE:
    http://dev.mysql.com/doc/refman/5.0/en/innodb-locking-reads.html

    You could write:

    $q = 'select id from table1 where is_delete = 0 limit 1 for update';
    $res = mysql_fetch_assoc(mysql_query($q));
    
    if($res) {
       $q = 'UPDATE table1 SET is_delete = 1 WHERE id = '".$res['id']."'';
       mysql_query($q);
    }
    

    See also: http://www.mysqlperformanceblog.com/2006/08/06/select-lock-in-share-mode-and-for-update/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have coded the next function. But surely someone has a more elegant way
I am trying to get values from a data set. My function has to
An exportable function has a struct as a one of the parameters. This DLL
In C the atan2 function has the following signature: double atan2( double y, double
If a function has a return type other than void , and the function
Can I figure out if a function has already been assigned to an event?
Having a problem where the form submits before the validateUsername function has a chance
I have set UserIsOnlineTimeWindow =2 in web.config then my logout() function has been modified
According to the standard, a conversion function has a function-id operator conversion-type-id , which
I have a function that has an array pointer passed it to modify stuff

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.