[UPHPU] correct transactions

Steve Dibb steve at wonkabar.org
Mon Jun 20 16:32:15 MDT 2005


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;');

Steve



More information about the UPHPU mailing list