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 June 1st, 2006, 09:48 AM
jpadie jpadie is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 2 jpadie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
PEAR::DB connecting to Access via ODBC - problems with dates

I am using the following code to access and query an ms access database.
php Code:
Original - php Code
  1.  
  2. $sql ="
  3. SELECT
  4.     Times.datDate,
  5.     [Project Details].strProjectName,
  6.     [Project Details].strCustomer,
  7.     Times.dblHours,
  8.     Times.memDescription
  9. FROM
  10.     [Project Details]
  11.     INNER JOIN
  12.         Times
  13.         ON
  14.         [Project Details].lngProjectID = Times.lngProjectID
  15. WHERE
  16.     Times.datDate
  17.     Between ? And ?";
  18.  
  19. $res = $db->getAll($sql, array("2006-05-01","2006-06-01") );


the connection works just fine and in my production code there is plenty of error checking.

the problem i have is formatting the dates correctly for inclusion in the query parameter. i have tried just about every combination i can think of and get, variously, empty result sets and errors. MS access seems to want something akin to a number but including the slashes and surrounded by hash signs.
ie
php Code:
Original - php Code
  1.  
  2. between #5/1/2005# And #6/1/2006#
  3.  


but of course we can't give this type of data in php as the hash sign is a commment designator. yes i could output a specific ascii character but this seems really backwards.

the relevant field type in access is date/time.

does anyone have any experience of how to use dates in queries to access databases across odbc using PEARB?

thanks
justin



Reply With Quote
  #2  
Old June 1st, 2006, 11:36 AM
jpadie jpadie is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 2 jpadie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: PEAR::DB connecting to Access via ODBC - problems with dates

to all those who take the time to read, there are two solutions...

solution 1 - replace the ? placeholder (which is for scalars) with the ! for literals. then forget the quirky access date format and use the standard yyyy-mm-dd variant.

solution 2 - replace the criteria with a single criterion
php Code:
Original - php Code
  1.  
  2. where format(datDate, 'mmmm') = ?

and set the array parameter to "May".

clearly solution 1 is more flexible and is the implementation i was after. The second is quite neat for ease of reference. I suspect that it may not be very efficient in terms of processing time however.

thanks
Justin

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPEAR Packages > PEAR::DB connecting to Access via ODBC - problems with dates


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