Assuming my $db var is a PDO connection to a MySQL db, is doing this:

$db->beginTransaction();

the same as doing this:

$db->query('START TRANSACTION');

??

    I do not know how this is handled by PDO. There may be a difference, and there may be no difference. I'm thinking along the lines of the differences between msyql and mysqli.

    It is possible to issue a mysqli::autocommit(false), followed after one or more queries by either mysqli::commit() or mysqli::rollback.
    You can achieve the same thing with mysql::query('START TRANSACTION'), ..., query('COMMIT/ROLLBACK'), and achieve the same results. The difference is that mysqli uses the API to start transactions as well as rollback/commit them, while doing it with mysql means that the query has to be parsed as any other query, which is slower.

    So the question is wether PDO parses the query and uses the database API or if PDO just passes the query along as any other query.
    Either way, if you use ::beginTransaction(), you should be on the right side.

      Write a Reply...