SunQuest
           PEAR Packages
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPEAR Packages

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old March 31st, 2005, 11:37 PM
sinceRe sinceRe is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 2 sinceRe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old April 1st, 2005, 12:03 AM
lig's Avatar
lig lig is offline
"Forum Nazi"
Codewalkers Demi-God (4500 - 4999 posts)
 
Join Date: Apr 2007
Location: Jacksonville, Fl
Posts: 4,720 lig User rank is Private First Class (20 - 50 Reputation Level)lig User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 20 m 53 sec
Reputation Power: 6
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):
php Code:
Original - php Code
  1.  
  2. $result = $DB->query('create record');
  3. if (PEAR::isError($result))
  4. {
  5.    $DB->rollback;
  6. }
  7. else
  8. {
  9.    $DB->commit;
  10. }

Reply With Quote
  #3  
Old April 1st, 2005, 05:32 PM
sinceRe sinceRe is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 2 sinceRe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPEAR Packages > PEAR DB_common::affectedRows() + MSSQL


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway