Laravel Road (transaction) MySQL transaction

Source: Internet
Author: User

Actually about MySQL transaction (OST MySQL statement), I have mentioned in my blog (MySQL article classification)

Today look at the processing of ORM based on Laravel framework

Get ready:

  The table must be a InnoDB engine

Db::BeginTransaction ();Try{    $name= ' abc '; $result 1= Test::create ([' name ' = = =$name]); if(!$result 1) {        /** * The parameters received by the Exception class * $message = "", $code = 0, Exception $previous = null*/        Throw New\Exception("1"); }    $result 2= Test::create ([' name ' = = =$name]); if(!$result 2) {        Throw New\Exception("2"); } DB::commit ();} Catch(\Exception $e) {DB:: Rollback ();//Transaction Rollback    Echo $e-GetMessage (); Echo $e-GetCode ();}

Note: If the ID is self-increment, the MySQL primary key is maintained in memory, and the transaction rollback is not a fallback ID, so there is a fault in the middle

Ext.: https://www.cnblogs.com/xj76149095/p/6222066.html

Laravel Road (transaction) MySQL transaction

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.