I am trying to use mysqli_rollback()
when a query fails. This nested sub-query should return null as 'qwerty' does not exist. However, no exception message is generated?
<?php
$con = mysqli_connect("x","y","z","zz");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
try {
mysqli_autocommit($con,FALSE);
mysqli_query($con,"INSERT INTO customer (id, name, mobile) values ((select id from somewhere where something = 'qwerty'), 'john', '01234567890')");
mysqli_commit($con);
} catch (Exception $e) {
echo 'Message: ' .$e->getMessage();
mysqli_rollback($con);
}
?>
CREATE customer table given below:
CREATE table customer
(
id int NOT NULL,
name varchar(100) NOT NULL,
mobile varchar(100),
PRIMARY KEY (id)
);