MySQL Transactions with PHP

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Kalar
Forum Newbie
Posts: 9
Joined: Sat Jul 27, 2002 2:04 am
Location: Saint John, Canada

MySQL Transactions with PHP

Post 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].
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
Kalar
Forum Newbie
Posts: 9
Joined: Sat Jul 27, 2002 2:04 am
Location: Saint John, Canada

Post by Kalar »

That was ridiculously stupid of me. I didn't check the main MySQL page in the PHP manual... :oops:

Thanks. :)
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

neither did I. It was just the first result of google :D
Post Reply