[UPHPU] correct transactions

Ray Hunter bigdog at venticon.com
Mon Jun 20 16:36:12 MDT 2005


Steve Dibb wrote:
> For those of you who use database transactions in your code, how do you
> handle them?  Do you send them all as one string or execute each query
> at a time?  I'm wondering what the "correct" way to do it is, if there
> is one.
> 
> The first way would be something like this:
> 
>     $sql = 'BEGIN TRANSACTION;';
>     $sql .= 'INSERT INTO foo VALUES bar;';
>     $sql .= 'INSERT INTO foo VALUES bar;';
>     $sql .= 'INSERT INTO foo VALUES bar;';
>     etc ..
>     $sql .= 'COMMIT TRANSACTION;';
> 
>     mssql_query($sql);
> 
> versus the second way which I'm playing with right now:
> 
>     mssql_query('BEGIN TRANSACTION;');
>     mssql_query('INSERT INTO foo VALUES bar;');
>     mssql_query('INSERT INTO foo VALUES bar;');
>     mssql_query('INSERT INTO foo VALUES bar;');
>     etc ..
>     mssql_query('COMMIT;');


create a unit test that utilizes both methods and then put a rollback at
the end. the verify if the data was rolled back or not.

That will be the ticket.

--
ray



More information about the UPHPU mailing list