Page 1 of 1

MySQL Transactions with PHP

Posted: Sun Sep 01, 2002 10:43 am
by Kalar
I remember reading a while back that PHP only allowed, for security reasons, one SQL statement to be executed at a time [excluding sub-queries] and that each SQL statement was always in auto-commit mode.

This being said, even if I were to use a transactionally-safe table type in MySQL, would it even be possible to use transactions within MySQL with a PHP front end?

I ask here because I haven't seen much information on it elsewhere [including the manuals].

Posted: Sun Sep 01, 2002 12:35 pm
by volka
haven't tried it yet, but there's a user contributed note in LXII. MySQL Functions
mbabcock-php@fibrespeed.net
28-Jul-2001 07:41

Since there aren't functions to start and end/rollback transactions, you'll have to use mysql_query("BEGIN"), mysql_query("COMMIT") and mysql_query("ROLLBACK"). These will only work properly on tables that support transactions. You may also wish to roll your own mysql_begin (etc) functions that run the above queries for you.

Posted: Sun Sep 01, 2002 10:06 pm
by Kalar
That was ridiculously stupid of me. I didn't check the main MySQL page in the PHP manual... :oops:

Thanks. :)

Posted: Mon Sep 02, 2002 2:00 am
by volka
neither did I. It was just the first result of google :D