0
The idea would be this: I have 3 classes, one for connection to the bank, another for Users and another for Product.
The User class with the database tb_usuarios.
The Product class with the database tb_produtos.
I do the INSERT in each User and Product class.
I am trying now on two objects to make a transaction with the code below.
try {
require_once 'Connection.php';
$conn = new Connection();
$conn->connectionDB()->beginTransaction();
$objuser = new Usuario();
$objuser->insertUser("Nome Teste", "[email protected]");
$objproduct = new Produto();
$objproduct->insertProduct("Nome Produto", "Preço", "Data");
$conn->connectionDB()->commit();
}
catch(PDOException $ex) {
$conn->connectionDB()->rollBack();
echo $ex.getMessage();
}
The fault occurs in the section below:
$conn->connectionDB()->rollBack();
If he entered the
catch. Failure occurs in thetry. What the$ex.getMessage();informs?– Andrei Coelho
Another thing that
$conn->connectionDB()->rollBack();cannot be used as the object$connwas not instantiated within thecatch.– Andrei Coelho