Php + Mysqli use transactions to handle transfer problem instances and mysqli transaction processing. Php + Mysqli use transactions to handle transfers. mysqli transaction processing this article describes how php + Mysqli uses transactions to handle transfers. Share it with you for your reference. The actual php + Mysqli uses transactions to handle the transfer problem instance, and mysqli transaction processing
This example describes how php + Mysqli processes the transfer problem using transactions. Share it with you for your reference. The specific implementation method is as follows:
<? Php header ("Content-type: text/html; charset = utf-8"); $ mysqli = new mysqli ("localhost", "root", "064319 ", "php"); $ mysqli-> set_charset ("utf8"); if ($ mysqli-> connect_errno) {die ('database connection failed '. $ mysqli-> connect_error);} $ mysqli-> autocommit (false); // set the automatic submission mode to false $ flag = true; // indicates whether the transaction is successfully executed. $ query = "update account set balance = balance-1000 where id = 3"; $ result = $ mysqli-> query ($ query ); $ affected_count = $ Mysqli-> affected_rows; if (! Result | $ affected_count = 0) {// failed $ flag = false;} $ query = "update account set balance = balance + 1000 where id = 2 "; $ result = $ mysqli-> query ($ query); $ affected_count = $ mysqli-> affected_rows; if (! $ Result | $ affected_count = 0) {$ flag = false;} if ($ flag) {$ mysqli-> commit (); echo 'transfer successful ';} else {$ mysqli-> rollback (); echo 'transfer failed';} $ mysqli-> autocommit (true ); // reset the transaction to automatic commit $ mysqli-> close ();?>
I hope this article will help you with php programming.
Examples in this article describes how php + Mysqli uses transactions to handle transfers. Share it with you for your reference. Details...