php and ms sql server and transaction

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
roguia
Forum Newbie
Posts: 8
Joined: Thu Feb 27, 2003 12:12 am

php and ms sql server and transaction

Post 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
User avatar
riley
Forum Commoner
Posts: 45
Joined: Thu May 02, 2002 6:31 pm

Post 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.
roguia
Forum Newbie
Posts: 8
Joined: Thu Feb 27, 2003 12:12 am

php and ms sql server and transaction

Post by roguia »

can you give me more explication about your code
thank you
User avatar
riley
Forum Commoner
Posts: 45
Joined: Thu May 02, 2002 6:31 pm

Post 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
roguia
Forum Newbie
Posts: 8
Joined: Thu Feb 27, 2003 12:12 am

php and ms sql server and transaction

Post by roguia »

thank you very much i will try it and tell you the result
drfunk
Forum Newbie
Posts: 2
Joined: Sat Apr 02, 2005 4:31 pm

hi

Post by drfunk »

Hi there,

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