Answer the question
In order to leave comments, you need to log in
How to work with transactions and prepared statement in php?
Good afternoon! My project uses PostgreSQL and PHP.
The question was - how can I do multiple inserts but be able to rollback at the end using pg_prepare ? I really need bind variables...
Answer the question
In order to leave comments, you need to log in
I recommend PDO.
$db = new PDO(....connect .... );
$db->beginTransaction();
if(
$db->exec('custom sql') &&
$db->exec('custom sql') &&
$db->exec('custom sql') &&
$db->exec('custom sql') &&
....
$db->exec('custom sql')
){
$db->commit();
} else {
$db->rollBack();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question