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