php + mysql still commiting

前端 未结 2 2008
清歌不尽
清歌不尽 2021-01-29 15:00

I have 3 mysql queries that I execute from php, 1 is successful and 2 are not. I have however set a commit and rollback. When I do a var_dump on the the commit it returns true,

2条回答
  •  走了就别回头了
    2021-01-29 15:24

    If you tell it to commit it will commit. It won't roll back just because there was an error in one of the statements. You have to check for errors each time you perform a query and then rollback if there is an error. Or just check at the end before committing:

    public function commit() {
    
        $mysqli=$this->db_connection;
        if ($this->error['State'] === 0) {
            $this->setError("Error: Please try again");
            mysqli_rollback($mysqli);
        } else {
            $c = mysqli_commit($mysqli);
            if ($c) return 1;
        }
    }
    

提交回复
热议问题