Page 1 of 1

php and ms sql server and transaction

Posted: Fri Mar 28, 2003 9:07 am
by roguia
good afternoon

how to use transaction in sql server exple i have to update multiple tables in my database but if an error occured i want to annulate(rollback) the operations
thank you

Posted: Fri Mar 28, 2003 7:15 pm
by riley
Personally I would write a stored procedure on the server and pass the appropriate parameters as a sql string to the stored procedure.

Code: Select all

$sSql = "Procedure 'val1', 'val2', uniqueId ";

mssql_query($sSql)
From there you will have complete control of the process, something that would seem most appropriate for sql.

php and ms sql server and transaction

Posted: Sun Mar 30, 2003 1:46 pm
by roguia
can you give me more explication about your code
thank you

Posted: Sun Mar 30, 2003 6:28 pm
by riley
Sure, php is not going to be able to handle errors as easily as you could if you are programming in sql. So with that in mind you can create a stored procedure that can examine the error codes returned by sql (returning error codes from sql to php is not very useful) and make any logical decisions needed.

A stored procedure can handle parameters:

storedprocname parameter1, parameter2, parameter3, parameter4

$sql = "procUpdate tab1, col2, value3, uid4";

In your stored procedure:


Begin Tran

Update tab1
Set col2 = value3
Where uid = uid4

If @errorlevel = 0
Commit
Else
Rollback

Hope this helps a little

php and ms sql server and transaction

Posted: Mon Mar 31, 2003 11:43 pm
by roguia
thank you very much i will try it and tell you the result

hi

Posted: Sat Apr 02, 2005 4:38 pm
by drfunk
Hi there,

Curious if the stored procedure method explained above worked for you when trying to implement transactions using the mssql extensions.