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 8494161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:13:26+00:00 2026-06-10T23:13:26+00:00

I have three php scripts on server1, server2, server3. I have remote mysql server4

  • 0

I have three php scripts on server1, server2, server3.
I have remote mysql server4 with database “watch” – table “mytable” with one column “data”

All these scripts connect to db “watch” table “watch” column “data” and all do the same operation:

  1. Select first row of column “data”
  2. Make operation with data
  3. Delete first row of column “data”
$connect = mysql_connect("ip","user","password") OR DIE("Can't connect ");
            mysql_select_db("watch") or die("Can't select database");
    $xv=1
    do {
    $select = mysql_query("SELECT data FROM mytable LIMIT 1") or 
               die("wrong select");
             if (!$select) {
             echo 'Could not run query: ' . mysql_error(); 
             exit;}
             $data = mysql_fetch_row($select);
    -----------
    operation with first row of "data" 
    -------------

    mysql_query("DELETE FROM mytable LIMIT 1") or die("wrong delete");

    } while ($xv++<100);

For example,

first row of “data” contains uniq value “Alex”.

second row of “data” contains uniq value “Michael”.

third row of “data” contains uniq value “George”.

PHP scripts run in cron at the same time but from different servers.

Is it possible that two or all three scripts select the same value of first row
“Alex”?

I would like to avoid that two or three scripts select simultaneously the same value of first row.

  • 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-10T23:13:28+00:00Added an answer on June 10, 2026 at 11:13 pm

    Use locking, unlocking of tables. LOCK TABLES explicitly acquires table locks for the current client session. UNLOCK TABLES explicitly releases any table locks held by the current session. Also read this link.

    $connect = mysql_connect("ip","user","password") OR DIE("Can't connect ");
    mysql_select_db("watch") or die("Can't select database");
    
    $xv=1
    do {
        mysql_query("LOCK TABLES mytable WRITE");
        $select = mysql_query("SELECT data FROM mytable LIMIT 1") or die("wrong select");
        if (!$select) {
             echo 'Could not run query: ' . mysql_error(); 
             exit;
        }
        $data = mysql_fetch_row($select);
    
    -----------
    operation with first row of "data" 
    -------------
    
        mysql_query("DELETE FROM mytable LIMIT 1") or die("wrong delete");
        mysql_query("UNLOCK TABLES");
    
    } while ($xv++<100);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three files: one called sql.php witch has a class db that I
I have three files in a folder 'test' one.php two.php print.html And i have
If I have three files index.php file.php and fns.php First example (it works): index.php
I have three update statements to be executed in PHP, i am getting the
i have a php loop which displays only one record even if there is
I have created three EC2 instances, two of instances are web servers and one
I have installed my PHP scripts which runs over Apache server in a Windows
I have three pages: Step1.php -> step2.php -> step3.php As it shows, after submitting
I have a php script to retrieve data from a MysQL databse following an
I have a fairly small MySQL database (a Textpattern install) on a server that

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.