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:
  #1  
Old March 5th, 2006, 08:28 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
DB Syntax Error on update query that runs successful in Query Analyzer

I am currently working on a site which uses Pear DB with PHP and MSSQL (SQL Server 2000). I have found an update query that is returning "DB Error: syntax error" when run from within the php application. What has me bogged down is, if I echo out this same query and run it in the SQL Server Query Analyzer - the query is successful.

Any ideas on why the validation results are different?

Not sure if this will help, but the code that I am debugging is as follows:
php Code:
Original - php Code
  1.  
  2. switch( $sQueryType ) {
  3.           case 'update':
  4.             foreach( $this->_aTableFields as $sTableName => $aTableFields ) {
  5.               if( 0 < count( $aTableFields )) {
  6.                 $aQueryParts = array();
  7.                 foreach( $aTableFields as $sFieldName ) {
  8.                   if( array_key_exists( $sFieldName, $this->_aUserInfo )) {
  9.                     $sTmp  = '';
  10.                     $sTmp .= $sFieldName . ' = ';
  11.                     $sTmp .= ''' . $this->_aUserInfo[$sFieldName] . ''';
  12.  
  13.                     $aQueryParts[] = $sTmp;
  14.  
  15.                   }
  16.                 }
  17.  
  18.                 if( 0 < count( $aQueryParts )) {
  19.                   $sUpdateQuery = 'UPDATE ' . $sTableName . ' SET ' .
  20.                                     implode( ', ', $aQueryParts ) .
  21.                                   ' WHERE ' . $this->_sUIDField . ' = '' . $sUID . ''';
  22. echo "<pre>" . print_r($sUpdateQuery,TRUE) . "</pre>";
  23.                   if( '' == $sQueryError ) {
  24.                     $sUpdateQueryResult =& $this->_oDBConn->query($sUpdateQuery);
  25.  
  26.                     if(( !$sUpdateQueryResult ) ||
  27.                        ( DB::isError($sUpdateQueryResult))) {
  28.                       $sQueryError = $sUpdateQueryResult->getMessage();
  29. echo "<pre>" . print_r($sQueryError,TRUE) . "</pre>";
  30.                     }
  31.                   }
  32.                 }
  33.               }
  34.             }
  35.             break;


Any advice would be greatly appreciated.

Thanks

JS

Reply With Quote
  #2  
Old March 6th, 2006, 12:35 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,727 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 1 h 4 m 45 sec
Reputation Power: 6
RE: DB Syntax Error on update query that runs successful in Query Analyzer

WOW - that is odd. If you don't know what part of the query is causing the problem - maybe break down the query to the basics and slowly add things in until you throw the error again.

Reply With Quote
  #3  
Old March 7th, 2006, 02:48 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: DB Syntax Error on update query that runs successful in Query Analyzer

Thanks for the input and the advice.

Unfortunately, I didn't pinpoint the exact culprit - however, the good news is that I made the following changes and the query is now successful in the PHP app as well as Query Analyzer.

What was really wierd is that not every query built in the loop was failing. It's one of those situations where I would love to know exactly what was going on there but don't have the time to devote to it. :-(

Anyway - below are the changes - incase your interested. Thanks again! JS

php Code:
Original - php Code
  1.  
  2.  
  3. $aQueryParts[] = "$sFieldName = '" . trim( $this->_aUserInfo[$sFieldName]  ) . "'";
  4.  
  5.                   }
  6.                 }
  7.  
  8.                 if( 0 < count( $aQueryParts )) {
  9.                   $sQueryParts = implode( ", ", $aQueryParts );
  10.                    
  11.                   $sUpdateQuery = "UPDATE $sTableName SET ";
  12.                   $sUpdateQuery .= "$sQueryParts";
  13.                   $sUpdateQuery .= " WHERE " . $this->_sUIDField . " = '" . $sUID . "'";
  14.  



Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPEAR Packages > DB Syntax Error on update query that runs successful in Query Analyzer


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 2 hosted by Hostway