Redbean: Getting Started (iv)-reflection mechanism and transaction

Source: Internet
Author: User
Tags dsn custom name

<?PHP//introducing the RB entry file    include_once' Rb.php '; //define DSN and related data    $dsn= ' Mysql:host=localhost;dbname=hwibs_model '; $user= ' Root '; $pass= ' '; $table= ' link '; //Link DatabaseR::setup ($dsn,$user,$pass); //Linked Data Tables    $handler= R::d ispense ($table); //Inspect:: Reflection table, returns the field structure of the table//1. Print it out in a one-dimensional array//2. If you do not pass a parameter, it is a one-dimensional array that reflects all of the table names [so if we want to get all the reflection of the table, we can take the second step, in the first step]    $result= R::inspect ();//or you can pass a table name in//adddatabase:: Build a communication pipeline [in fact, multiple database handles]R::adddatabase ("J1",$dsn,$user,$pass);//The first parameter is a custom nameR::adddatabase ("J2",$dsn,$user,$pass); R:: Adddatabase ("J3",$dsn,$user,$pass); R:: Adddatabase ("J4",$dsn,$user,$pass); //selectdatabase:: Select an established communication pipeline [do not know the meaning of such a switch is what good???? ]//1. Of course, you can pass in "default" to select a pipeline that you originally set up by Setup.R::selectdatabase ("J4"); R:: Freeze (true); //The transaction operation//1.begin opens a transaction//2. Performs a store operation or exec operation//3. Catches an exception and needs to roll back the transaction//4 if an exception occurs. Otherwise, the transaction is committed normally    Try{R::begin (); R:: Store ($handler); R::commit (); }Catch(Exception $e) {R::rollback (); }        //Transactional operations:: No big use to see, in fact, is to begin, commit or failure of the rollback system integration,//1. All we have to do is execute SQL//2. But notice that the MySQL auto-commit feature is turned off.R::transaction ("T1"); functionT1 () {Echo' Execute store or exec '; }        ?>

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.