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
php and ms sql server and transaction
Moderator: General Moderators
Personally I would write a stored procedure on the server and pass the appropriate parameters as a sql string to the stored procedure.
From there you will have complete control of the process, something that would seem most appropriate for sql.
Code: Select all
$sSql = "Procedure 'val1', 'val2', uniqueId ";
mssql_query($sSql)php and ms sql server and transaction
can you give me more explication about your code
thank you
thank you
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
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
thank you very much i will try it and tell you the result