S
S
Sergey2014-07-01 19:35:49
PHP
Sergey, 2014-07-01 19:35:49

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

3 answer(s)
V
Vit, 2014-07-01
@Tookuk

PDO has everything for this www.php.net/manual/ru/book.pdo.php

V
Volodymyr Godyak, 2014-07-02
@wmgodyak

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 question

Ask a Question

731 491 924 answers to any question