my problem is , i have a database design from this link is my database overdesigned?
edit* ok maybe useing transaction ? but where should i put the rollback if it fails ?
$dbConnect->beginTransaction();
$RegisterInsert = $dbConnect->prepare("INSERT INTO companies (
`name`, `address`, `email`, `phone`, `link`, `verified`) VALUES (
:name, :address, :email, :phone, :link, :verified)");
$RegisterInsert->execute($RegisterData);
$RegisterData2['CID'] = $dbConnect->lastInsertId();
$RegisterInsert = $dbConnect->prepare("INSERT INTO users_companies (
`UID`, `CID`, `role`) VALUES (
:UID, :CID, :role)");
$RegisterInsert->execute($RegisterData2);
$dbConnect->commit();
where should i put the rollback ?
Thanks
A transaction should end with either a
rollback()or acommit(), (only one of them)Its usually used with an
if...elsestatement as logically only one of them should be executed.Transactions are usually used when there is a complex logic involved with queries.
In case you are using MySQL, make sure you are not using MyISAM engine for tables, as it doesn’t support transactions.