PHP mysqli Learning (vi) Things

Source: Internet
Author: User

Autocommit (0) Close transaction autocommit

Commit () Commit

Rollback () rollback

<?PHPHeader(' Content-type:text/html;charset=utf-8 ');$mysqli= @NewMysqli (' localhost:3306 ', ' root ', ' root ', ' Zhy ');if($mysqli-Connect_errno) {     die(' Mysqli Connect error: '.$mysqli-connect_error);}$mysqli->set_charset (' UTF8 ');$mysqli->autocommit (FALSE);$sql _add= ' Update account Set money = Money + ' WHERE username = ' User1 ';$sql _reduce= ' Update account set money = money-100 WHERE username = ' User2 ';$res _add=$mysqli->query ($sql _add);$rows _add=$mysqli-affected_rows;$res _reduce=$mysqli->query ($sql _reduce);$rows _reduce=$mysqli-affected_rows;if($res _add&&$res _reduce&&$rows _add>0 &&$rows _reduce>0){    $mysqli-commit (); Echo' Transfer success <br/> '; $mysqli->autocommit (TRUE);}Else{    $mysqli-rollback (); Echo' Transfer failure <br/> ';}$mysqli->close ();

PHP mysqli Learning (vi) Things

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.