search

Home  >  Q&A  >  body text

php - What is the difference between hook function and transaction?

Think they are all the same? Is it because something unexpected happened to the hook function that it will not be executed?

过去多啦不再A梦过去多啦不再A梦2817 days ago579

reply all(1)I'll reply

  • 世界只因有你

    世界只因有你2017-05-16 13:01:49

    Hook function: It can be simply understood as the point where the behavior occurs, such as the login process (submit account password->Verify account password->Verify whether account is locked->Return login result), you can perform the above four steps Set a hook at any point, and then perform extended processing (for example, I may implement a hook function at the point of "verify account and password" to obtain the submitted account and password as "001/111", then the submitted data will be Change it to "user_001/pass_111", and then when the program actually compares in the database, it compares the account password "user_001/pass_111").
    Transaction: refers more to the database level, such as a transaction process. When Zhang San transfers 100 to Li Si, it will be divided into two steps: 1. Deduct 100 from Zhang San's account; 2. Add 100 to Li Si's account. Then we must ensure that both operations succeed or both fail to be considered correct, which requires a transaction. A business is something that treats a number of small steps as a whole big step. These small steps will either all succeed or fail, and some will succeed and some will fail.
    The process of the transaction is:
    1, start the transaction
    2, and execute the small steps a, b, c, d...
    3, if all are executed successfully, submit the transaction (the database permanently saves all changes)
    4, If any small step fails, roll back the transaction (the database restores the data changes made and returns to the state of the data before the transaction was started)

    reply
    0
  • Cancelreply