PHP simple transaction test case-PHP source code

Source: Internet
Author: User
PHP simple transaction test cases
Show engines; + Region + --------- + Region + -------------- + ------ + ------------ + | Engine | Support | Comment | Transactions | XA | Savepoints | + Region + --------- + Region + -------------- + ------ + ------------ + | FEDERATED | NO | Federated MySQL storage engine | NULL | MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | MyISAM | YES | MyISAM storage engine | NO | BLACKHOLE | YES |/dev/null storage engine (anything you write to it disappears) | NO | CSV | YES | CSV storage engine | NO | MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | ARCHIVE | YES | Archive storage engine | NO | InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES | PERFORMANCE_SCHEMA | YES | Performance Schema | NO | + -------------------- + --------- + Upper + ------------ + ------ + ------------ + // schemalcreate table transaction_tbl (name char (10) not null) engine = innodb; */class Transaction {// determines whether the inserted query is successful. private $ error = 0; // connects to the Resource private $ conn_id = null; public function _ construct () {$ this-> connect ();} public function test () {echo "begin test \ n "; // start transaction $ this-> beginTransaction (); // Insert test data // The name size limit is 10 $ str1 = str_repeat ("a", mt_rand (1, 13); $ str2 = str_repeat ("B", mt_rand (1, 13); $ this-> query ("INSERT INTO 'transaction _ TBL' ('name ') VALUES ('$ str1') "); $ this-> query (" insert into 'transaction _ TBL' ('name') VALUES (' $ str2 ')"); // submit the query if ($ this-> error = 0) {$ this-> commit ();} else {$ this-> rollback ();} echo "end test \ n";} private function query ($ SQL) {echo $ SQL. "\ n"; (mysql_query ($ SQL, $ this-> conn_id) = FALSE) & ++ $ this-> error ;} // start the private function beginTransaction () {mysql_query ("BEGIN", $ this-> conn_id);} // roll back the private function rollback () {echo "ROLLBACK \ n"; mysql_query ("ROLLBACK", $ this-> conn_id);} // submit private function commit () {echo "save done \ n "; mysql_query ("COMMIT", $ this-> conn_id);} // connect to the database private function connect () {$ this-> conn_id = @ mysql_connect ("127.0.0.1 ", "root", "") or die ("can \'t connect :". mysql_error (); mysql_select_db ("test", $ this-> conn_id) or die ("can \'t use test :". mysql_error ();} // close the data private function close () {mysql_close ($ this-> conn_id);} public function _ destruct () {$ this-> close () ;}$ trans = new Transaction (); $ trans-> test ();

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.