How to Use database transactions in Yii _ PHP Tutorial

Source: Internet
Author: User
Tags php database
Summary of the usage of database transactions in Yii. Summary of the usage of database transactions in Yii the Yii Framework supports database transaction processing. For more information about transactions, see the article on this site: summary of how to use database transactions in Yii

The Yii Framework supports database transaction processing. For more information about transactions, see the article on this site:

About database (MySQL) transactions

Transactions are generally used when batch deletion is encountered in a project. we will share a usage example below.

 Array ('username' => 'phpernote. com_0 ', 'password' => '000000'), 1 => array ('username' => 'U _ 1', 'password' => '000000 '), 2 => array ('username' => 'U _ 2', 'password' => '000000'); $ transaction = Yii: app () -> db-> dbConnection-> beginTransaction (); // here db represents the definition in main. php database connection object dbtry {Yii: app ()-> db-> createCommand ()-> insert ('tbl _ user', $ array [0]); Yii:: app ()-> db-> createCommand ()-> insert ('tbl _ user', $ array [1]); Yii: app () -> db-> createCommand ()-> insert ('tbl _ user', $ array [2]); $ transaction-> commit ();} catch (Exception $ e) {$ transaction-> rollback ();}

Note: If you are using a MySQL database, the table engine must be of the innodb type. because the MyISAM engine of the MySQL database does not support transaction processing, the above code will not achieve the expected purpose.

Articles you may be interested in
  • Mysql database cache function analysis, debugging, and Performance Summary
  • Yii database addition, modification, and deletion operations summary
  • Differences between Database (MySQL) stored procedures and transactions
  • About database (MySQL) transactions
  • Yii database query operation summary
  • Summarize the causes and solutions for the slow MySQL database server
  • In php, we use the curl post method to submit data and the get method to obtain webpage data.
  • Case sensitivity of mysql databases

The policyii framework supports database transaction processing. For more information about transactions, see the article on this site...

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.