De: Jaime Garcia [mailto:jgarcia@vali.com.mx]
Enviado el: Miércoles, 17 de Diciembre de 2008 01:43 p.m.
Para: 'Olivier Ricordeau'
Asunto: RE: [fw-db] Problem with transactions
Oliver:
DTL queries aren't part of MySQL transactions at all, only DML queries are.
Regards!
-----Mensaje original-----
De: Olivier Ricordeau [mailto:olivier@ricordeau.org]
Enviado el: Miércoles, 17 de Diciembre de 2008 11:18 a.m.
Para: fw-db@lists.zend.com
Asunto: Re: [fw-db] Problem with transactions
Olivier Ricordeau a écrit :
> Hi list,
>
> I'm trying to do a transaction with ZF (for the first time) and I can't
> make it work...
>
> Here is my code:
>
> -------------------------------------------------------
>
> $db = Zend_Registry::get("db");
> // Start a transaction
> $db->beginTransaction();
> try {
> // Run a query that works
> $db->query("CREATE TABLE test ("
> . "test_id INT UNSIGNED NOT NULL AUTO_INCREMENT,"
> . "PRIMARY KEY (test_id)");
FYI, it doesn't work even if I create the "test" table using InnoDB in
the code line above.
> // Run a wrong query on purpose
> $db->query("This is not a valid SQL query!");
> } catch (Exception $e) {
> $db->rollBack();
> print "An exception occured!\n";
> exit(1);
> }
> // No exception was caught while doing the transition, we can
> // commit the transaction.
> $db->commit();
>
> ----------------------------------------------------
>
> This code catches the exception correctly and displays "An exception
> occured!", but the "test" table is present in the DB after the script's
> execution...
>
> I'm new to SQL transactions, so what did I miss here?
>
> Cheers,
> Olivier
>
> PS: I'm using the pdo_mysql adapter. I tried with mysqli and it leads to
> the same result.
>
--
- *Olivier RICORDEAU* -
olivier@ricordeau.org
没有评论:
发表评论