|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
PEAR DB_common::affectedRows() + MSSQL
Hello,
I was hoping someone could sheld some light on a little problem I'm having with PEAR and MSSQL. I need to perform a transaction which starts with an initial query which will in turn tell what the next action is to come and that in turn will commit or rollback the first query. But I can't get a response back telling me if the first query was successful or not. I've tried using DB::affectedRows();and DB::query('SELECT @@ROWCOUNT AS RowsAffected'); They both return a true value no matter what the outcome of the first query is. I'm just trying to figure out if this is a MSSQL + PEAR + PHP thing or I'm doing something wrong. The program runs something like this : [highlight=php] DB::query('create record'); $rowsAffected = DB::affectedRows(); if ($rowsAffected) { DB::commit } else { DB::rollback } Any help would be much appreciated. Thanks, Alex |
|
#2
|
||||
|
||||
|
RE: PEAR DB_common::affectedRows() + MSSQL
Generally speaking - if the query comes back true the sql has been completed. Assuming you are basing your decision on the outcome of that query being done or not you can just use the PEAR::isError($result) check. So using your example (assumes you are using the DB package):
|
|
#3
|
|||
|
|||
|
RE: PEAR DB_common::affectedRows() + MSSQL
Thanks for replying back.
Your example is correct, and that will satisfy to a point. The problem with using DB:isError() is that DB::query('INSERT|UPDATE|DELETE') returns a DB_error::getCode() of -1 (as long as the sql statement is properly formed and executes), which while using DB:isError() will see it as an error. To bybass that I used a custom error handler that would weed out all the codes of -1 (since those seemed to be properly formatted sqls, but returned nothing (not 0 records)). I then proceeded to use DB::affectedRows(), which unfortunately also only works to a point. If you have a set up like this DB Record : ID | Name 15 | Alex 18 | lig .... .... And you want to update ID = 15 UPDATE table SET Name = '...' WHERE ID = 15 This is a correct sql statement and would query and return no errors, and would make the update. DB::affectedRows = 1, correct. But if by the force of nature, the ID were to be wrong let say : UPDATE table SET NAME = '...' WHERE ID = 15000 Which for this example that record does not exist, but the sql statement is still a valid one and will run properly, but no row will be affected. DB::affectedRows = 1, hmmm..? I'm unsure if this is a MSSQL specific thing, or just an all around PEAR thing. Will need to test that out. Oh well, guess I'm doing this the long way. Thanks! Alex |
![]() |
| Viewing: Codewalkers Forums > PHP Related > PEAR Packages > PEAR DB_common::affectedRows() + MSSQL |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|