Summary of using database transactions in Yii

Source: Internet
Author: User
Tags php database

Summary of using 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.

<? Php $ array = array (0 => 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

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: 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.