Re: mssql_query & ROLLBACK
| From: | Frank M. Kromann | Date: | Mon, 24 Mar 2003 23:53:07 +0000 |
| Subject: | Re: mssql_query & ROLLBACK | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-26609@lists.php.net to get a copy of this message | ||
Hi,
You can't split a transaction between multiple calls to mssql_query. The
memory used (in the server and client) are cleared between each call.
You would have to create a batch of statements and execute these with one
call to mssql_query.
- Frank
> I have an opened connection to MS SQL Server 7
> and I try to do this:
>
> $commit = FALSE;
>
> // SELECT @@TRANCOUNT returns 0 here = OK
>
> if(mssql_query("BEGIN TRANSACTION")) {
>
> // SELECT @@TRANCOUNT returns 1 here = OK
>
> if(mssql_query("INSERT INTO TABLE (DATE) VALUES ('$date')")) {
>
> // ...
>
> $commit = TRUE;
> }
>
> if($commit) {
> mssql_query("COMMIT TRANSACTION");
> return TRUE;
> }
> else {
> mssql_query("ROLLBACK TRANSACTION");
> return FALSE;
> }
> }
> else
> return FALSE;
>
> When INSERT is done without errors, everything is OK.
> But when it is not possible to insert data into a table
> for any reason, SQL server returns this error message:
>
> The ROLLBACK TRANSACTION request has no corresponding BEGIN
> TRANSACTION. (severity 16) in ... .php
>
> But using SELECT @@TRANCOUNT I can check that TRANSACTION
> is started, I tried to name the transaction, it didn't help.
>
> I thought it is because I can't COMMIT/ROLLBACK empty
> transaction, but this works fine:
>
> mssql_query("BEGIN TRANSACTION");
> mssql_query("ROLLBACK TRANSACTION");
>
> What's wrong?!?
>
>
> --------------------
> Zmìò se díky novým, barevným èoèkám FreshLook! Nyní akèní nabídka.
http://user.centrum.cz/redir.php?url=http://www.cibavision.cz
>
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>