Rollback does not do anything when error occurs in my transaction mysql

I have written code to insert multiple rows in a table. If there is an error on any of them, I want them to rollback.

The code is written in PHP:

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
$conn->autocommit(false);
$conn->begin_transaction();
try {
    $projectsLoaded = "";
    foreach ($data as $key => $value){
        if ($key === "palette__for__"){
            // palette data to save to userpalettes
            $stmt = $conn->prepare("UPDATE userpalettes SET userId = ?, paletteData = ?, dataSize = ?");
            $paletteData = $value;
            $dataSize = strlen($value)/1024;
            $stmt->bind_param("ssd", $userId, $paletteData, $dataSize);
            $stmt->execute();
        }
        else if ($key === "searches__for__library__patterns" || $key === "__symbols__color__map__" ||
                 $key === "default_project_in_local_storage" || $key === "hints__on__off__local__storage"){
            continue;
        }
        else {
            // patterns should have bg, fg and grid keys in them
            try {
                $pattern = json_decode($value);
                error_log(print_r($pattern, true));
            }
            catch(Exception $e){
                continue; // skip
            }
            if (property_exists($pattern, 'bg') && property_exists($pattern,'fg') && property_exists($pattern,'grid')){
                 $projectName = $key;
                 // write to userprojects table
                $stmt = $conn->prepare("INSERT INTO userprojects (userId, projectName, projectData, dataSize) VALUES (?, ?, ?, ?)");
                $projectData = $value;
                $dataSize = strlen($value)/1024;
                $stmt->bind_param("sssd", $userId, $projectName, $projectData, $dataSize);
                $stmt->execute();
                $projectsLoaded = $projectsLoaded.",".$projectName;
            }
            else {
                continue;
            }
        }
    }
    echo "Success:".$projectsLoaded;
}
catch(Exception $e){
    $conn->rollback();
    $conn->close();
    echo("Error: Exception while inserting data: ".$e->getMessage()." Line:".$e->getLine()." Rolled back");
}

I am still in the process of testing this code and it’s the first time I have tried to use a transaction.

I have noticed that when an Exception occurs, I am getting back the error message at the bottom, so rollback() has executed, but the tables then contain inserted data up to the point of the error.

This is also the first time I have used prepared statements, so am wondering if that causes some problem also.

Is there something wrong with the statements I am using? Or is it a problem with my database not supporting transactions?

I am using a mysql db that was installed as part of a WAMP server installation. Don’t know too much about it other than that, but I have been using it as my test system for quite some time and have had no problems. But, maybe the transaction stuff does not work on it?

I looked up possible problems and I found that others were using the autocommit(false) statement. One place said to do this before begin_transaction, but I have also seen it without a begin_transaction following it.

Should I be using autocommit(false) in place of begin_transaction? Does it matter?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật