PHP time stamp examples to explain _php tutorial

Source: Internet
Author: User
Everyone toWe are bound to encounter this situation: Bank A and Bank B almost simultaneously open your account and see your account on the original 1000 yuan deposit, and then both banks want to add 500 yuan deposit to your account. Then, bank A will change $1000 to $1500 and Bank B will change $1000 to $1500. That's a bad thing! Finally, your bank account last only 1500 yuan instead of the supposedly 2000 yuan, equals the loss of 500 yuan in vain! This is the serious problem caused by the modification without locking the data. However, we can solve this problem skillfully by PHP timestamp.

Let's look at the idea:

In the Bank Account table, set the PHP timestamp field timestamp to text type varchar.

When bank a reads the deposit field in the Account table, it also reads the timestamp field, such as 123456.

When bank a modifies the value of the deposit, the previous read timestamp of 123456 is compared with the PHP timestamp in the current table, and if it is consistent, the disk is saved and a new timestamp is generated, such as a timestamp of 456789 in the replacement table 123456.

What good would that do?

Let's look at the beginning of the situation: Bank A and Bank B almost simultaneously open your account and see your account on the original 1000 yuan deposit, while the two banks simultaneously read the timestamp 123456, then there is a difference, when bank a 1000 yuan into 1500 yuan, save, The system will compare the previous timestamp 123456 to the time stamp in the table when the disk was saved, obviously, it should now be consistent, then allow to save and generate a new timestamp 456789 to replace the old timestamp 123456. Next, bank B also changed 1000 yuan to 1500 yuan, save, the system compared to the previous timestamp 123456 is the same as the time stamp in the table, found that the previous timestamp 123456 has been different from the current time stamp 456789, the system refused to disk, the request to refresh the data, After the data refresh 1000 yuan already because before a bank deposited 500 yuan and became 1500 yuan, then Bank B will be on the basis of 1500 yuan to 2000 yuan, save again, the system allows. In this way, we avoid the error of repeating data changes!

Some like tongue twisters, hope everybody already understood my meaning ~

Finally, let's look at some of the operating code for PHP timestamps.

Get time stamp

 
  
  
  1. Php
  2. $ Time timestamp =time ();
  3. Echo $timestamp;
  4. ?>

Update the SQL statement for timestamp:

Update table name set field name = $timestamp WHERE condition = value;


http://www.bkjia.com/PHPjc/446425.html www.bkjia.com true http://www.bkjia.com/PHPjc/446425.html techarticle we are bound to encounter this situation: Bank A and Bank B almost simultaneously open your account and see your account on the original 1000 yuan deposit, and then both banks want to be in your account ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.