0

Im doing a transaction, but for some reason if one o the sentence is wrong, it will just ignore it and execute the next one, using MYSQL - XAMPP , heres the code:

public static function finishpackage($room, $finish_date) {
    $connection = self::connect();
    $connection->beginTransaction();

    try {

        $query = $connection->prepare("INSERT INTO `finished_products` 
        (room, name, lot, quantity_packed, pallet, start_date) SELECT room, name, lot, quantity_to_package, finished_pallets, 
        start_date FROM `current_products` WHERE `room`=:room");
        $query->execute(["room"=>$room]);

        $query = $connection->prepare("UPDATE `finished_products` SET `finish_date`=:finish_date WHERE `room`=:room");
        $query->execute(["finish_date"=>$finish_date, "room"=>$room]);

        $query = $connection->prepare("DELETE FROM `current_products` WHERE `room`=:room");
        $result = $query->execute(["room"=>$room]);

        $connection->commit();

    }catch(PDOException $e) {
        $connection->rollBack();
        return $e->getMessage();
    }
}

for example, if the name of the table of the second sentence was wrong it shouldnt execute neither of them, but it just ignore the second sentence and execute the next one, executing only the insert and the delete sentence, why is this happening?, my DB motor is INNODB and i dont know if theres a different way to write the transaction with INNODB instead of MyISAM, Thanks :)

Nigel Ren
  • 56,122
  • 11
  • 43
  • 55
plus
  • 327
  • 3
  • 12
  • Is PDO set to throw exceptions on errors - https://stackoverflow.com/questions/8992795/set-pdo-to-throw-exceptions-by-default – Nigel Ren Jun 20 '20 at 06:48
  • added the exception array to the connection, but it stills doesnt work well, now it just delete but doesnt insert and update – plus Jun 20 '20 at 07:43

0 Answers0