I'm making a CRUD with php and postgres, and I want to know if there a way to rollback the transaction if there is a error. actually if I get an error in the transaction the id (primary key) get increased, then I lose one id for the future use.
How can I prevent it? I mean, if the Insert's Query fails, don't make the auto increment in the table.
Im using a class for execute the querys:
public function insertRecord ($data){
$campos =$this->getTableFields();
$data =implode ("', '", $data);
$sql ="INSERT INTO {$this->table} ($campos) VALUES (";
$sysData =$this->getDefaultValues();
if($sysData){
$sysData .= ",";
$sql .="$sysData ";
}
$sql .="'$data') RETURNING {$this->campoId};";
echo $sql;
pg_query($this->linkid,$sql);
return $this->validateOperation();
}