php + mysql still commiting

前端 未结 2 2007
清歌不尽
清歌不尽 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;
        }
    }
    
    0 讨论(0)
  • 2021-01-29 15:48

    The issue was that the tables were isam and the database was innoDB. When I changed the tables to innoDB it started working.

    0 讨论(0)
提交回复
热议问题