This topic is locked

SQL Server BEGIN TRANSACTION / COMMIT / ROLLBACK

4/27/2023 2:32:15 PM
PHPRunner Tips and Tricks
M
mfonseca author

Hi all,
I'm trying to implement transactions with SQL Server, but its not working as desired.
I've following this tip https://asprunner.com/forums/topic/28886-Mysqli-commint-and-rollback but was unable to make it work.
I've tried also
DB::Exec(BEGIN TRANSACTION);
...
DB::Exec(COMMIT);
...
DB::Exec(ROLLBACK);
but the rollback is not being done in the SQL Server Database.
Any suggestions? or example?
Thanks

fhumanes 4/30/2023

Hi @mfonseca.
You have used the "commands" of MySQL transactions and you must use the MSSQL.
Look at the examples of this URL: https://learn.microsoft.com/es-es/sql/t-sql/language-elements/begin-transaction-transact-sql?view=sql-server-ver16
Greetings,
fernando

M
mfonseca author 5/3/2023

Hi Fernando,
Thank you for the reply.
I had already used the SQL Server commands, but was not working.
I had the BEGIN TRANSACTION, outside a while ($data = $rs -> fetchAssoc()) { .... } segment and it was not working.
When I moved it inside the program it started to work.
Thanks again.
P.S. - by the wy, thanks for all your info and tutorials on phprunner.
They have helped me a lot.