You are here: Re: Transactions in PHP on SQL Server 2005 « PHP Programming Language « IT news, forums, messages
Re: Transactions in PHP on SQL Server 2005

Posted by Jerry Stuckle on 07/15/06 03:29

~john wrote:
> I'm trying to get a transaction to work with PHP 5.1.4 and SQL Server
> 2005... The first SQL statement deletes several rows in the database.
> The next SQL statement loops through and inserts several rows into the
> same table. What I'm wanting is for the database to rollback all
> transactions if any 1 of the inserts fail. What's happening now is the
> DELETE statement runs successfully deleting several rows... but as soon
> as one of the INSERTS fail, the page errors out WITHOUT rolling back
> the DELETE statements. What am I doing wrong in my code?
>
> thanks,
>
> ~john
>
>
>
> mssql_query("BEGIN TRAN");
>
> $sql = "DELETE FROM MyTable WHERE Value > 0";
>
> $result = mssql_query($sql);
>
> foreach(loopVar as val)
> {
> $sql = "INSERT INTO MyTable VALUES(1)";
> $result = mssql_query($sql);
>
> if( ! $result ){
> mssql_query('ROLLBACK TRAN');
> exit;
> }
>
> }
>
> mssql_query("COMMIT TRAN");
>

John,

Why not try asking in a MySQL newsgroup, like comp.databases.mysql?


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация