It's my first time working with Firebird database and I need some help in the transactions department. I need to run multiple functions inside a ''main function'', those functions have queries, but if one fails, I need them all to rollback. Can I open the transaction in the top of the main function and close it at the bottom or do I have to open and close for each query? I'll post an example.
public function Main_function()
{
$id = $this->create_user_id();
$connection = ibase_connect($this->_db, $this->_username, $this->_password, '100');
$trans = ibase_trans($connection, IBASE_READ+IBASE_COMMITTED+IBASE_REC_NO_VERSION);
$query = "INSERT INTO USERS (user_id, name) VALUES ('john', '$id')";
$newuser = ibase_query($trans, $query);
$return = $this->insert_new_job($id);
ibase_commit($trans);
ibase_close($connection);
}
public function create_user_id()
{
$id = '2';
return $id;
}
public function insert_new_job($id)
{
///DO I NEED TO OPEN A NEW TRANSACTION OR THE OTHER IS STILL ACTIVE?
$query = "INSER INTO jobs (name, id, job) VALUES ('john',$id,'developer') ";
$result = ibase_query($trans, $query);
return $result;
}