使用mysqli_begin_transaction()时服务器版本错误

I am building an application using a local server (Xammp). First I turn off default autocommitt before beginning a transaction like so:

      if($condition == true){
      mysqli_autocommit($mysqli, FALSE);//disabling default autocommit
      // Starting transaction for read and write  
      mysqli_begin_transaction($mysqli, MYSQLI_TRANS_START_READ_WRITE);
      //....Update table
       mysqli_commit($mysqli);//commit records to database
       }else {
         mysqli_rollback($mysqli);}

If I click a button, I am getting the error message telling me that my server version does not support mysqli_begin_transaction() minimum required is 5.6.5.Tf i check in the database the results are as expected except that the user is not redirected anywhere,the browser displays this error message

Warning: mysqli_begin_transaction(): This server version doesn't support 'READ WRITE' and 'READ ONLY'. Minimum 5.6.5 is required in C:\xampp\htdocs\wezhira\foo.php on line 38

Is there anyone who can help me on how to upgrade my server to test my application any links blogs or articles will be helpful,secondly,Will this error disappear if I use a live server.I have seen some solutions here on Stackoverflow suggesting that mysqli_begin_transaction()can be replaced by mysqli_autocommit($mysqli, FALSE); How true is this statement?

I realised that this error is due to the innodB version your mysql is running currently. Xampp comes with MariaDB and their latest version of innodB is 5.6.34-79.1. So you might want to upgrade the db or use autocommit() instead.

Run this code on your phpmyadmin SQL query to find out your version of Innodb

SHOW GLOBAL VARIABLES LIKE '%version%'

if your version is truely below 5.6.5 then, consider re-writing your code with autocommit() which is quite similar to transaction. To use autocommit, refer to this php documentation php autocommit documentation

autocommit() will work on your current version of innodB. little changes are required when migrating your code from Transaction to autocommit(). Here is a code sample.

function failed_to_pay($package, $payer){
    global $sponsor;
    global $payer_id;
    require 'config.php';

    $mysqli = new mysqli($db_host, $db_user, $db_password, $db_name); //New connection to the Database

        if ($mysqli->connect_errno) {
            printf("Connect failed: %s
", $mysqli->connect_error); //Check for Error in connection
            exit();
        }


        try{
            $mysqli->autocommit(FALSE); //Begin Transaction Using Autocommit function set to false
            $flag = true; //Use this to check for error

            $update_sponsor = $mysqli->query("UPDATE $package SET $payer = '' WHERE id = '$sponsor'");
                if(!$update_sponsor){
                    $flag = FALSE;
                }

            $delete_payer = $mysqli->query("DELETE FROM $package WHERE id = '$payer_id'");
                if(!$delete_payer){
                    $flag = FALSE;
                }

            if ($flag){
                $mysqli->commit(); //commit the transaction
                $mysqli->autocommit(TRUE); //set auto commit to true
                $mysqli->close();
                echo '<div class="alert alert-success"> You have been exited from this Package Successfully</div>';

                echo '<script>window.setTimeout(function() {
                window.location.href = "manage_acct.php";
                }, 3000);</script>';
            }
            else{
                $mysqli->rollback();
                $mysqli->autocommit(TRUE);
                $mysqli->close();
                echo '<div class="alert alert-warning"> Oops! We could not exit you from the Package. Please try again Later</div>';

            }

        }

        catch(Exception $e){
            $mysqli->rollback();
            $mysqli->autocommit(TRUE);
            $mysqli->close();
            echo '<div class="alert alert-warning"> Oops! An Error occurred: '. $e . '</div>';
        }
}

If MySQL / InnoDB is up to date - try to check php version. I changed from 7.3 to 7.2 and it helps.