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 April 12th, 2007, 05:37 PM
wputler wputler is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 2 wputler User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
MDB2 loadmodule extended

Hi - just trying my first MDB2 and having trouble already.

This works, so I know I've got the right dsn and it's finding MDB2.

php Code:
Original - php Code
  1.  
  2.     // Data Source Name: This is the universal connection string
  3.     $dsn = 'mysql://' . $user . ':' . $pass . '@' . $host . '/' . $mdb2_name;
  4.    
  5.     $mdb2 =& MDB2::factory($dsn);
  6.  
  7.     $mdb2->loadModule('Extended', null, false);
  8.  
  9.     if (PEAR::isError($mdb2)) {
  10.         echo ($mdb2->getMessage().' - '.$mdb2->getUserinfo());
  11.     }
  12.  
  13. $query ='SELECT * FROM mytable';
  14.  
  15. // run the query and get a result handler
  16. $result = $mdb2->query($query);
  17.  
  18. // check if the query was executed properly
  19. if (PEAR::isError($result)) {
  20.     echo ($result->getMessage().' - '.$result->getUserinfo());
  21.     exit();
  22. }
  23.  
  24. // lets just get row:0 and free the result
  25. $array = $result->fetchRow();
  26. $result->free();
  27. var_dump($array);


So far, so good. Now I want to retrieve all the rows. So I decide getAssoc would be the perfect thing. But if I try to use getAssoc, I get the following error:

Call to undefined function: getassoc() in /blah/blah....

Here is my code for getting the Assoc array:

php Code:
Original - php Code
  1.  
  2. $sql = 'SELECT DISTINCT category FROM nrg_categories ORDER BY category';
  3. $arr_categories = & $mdb2->getAssoc($sql);


This has to be easier than I'm making it. Why won't it load the Extended class and why doesn't it give me an error - or am I referencing getAssoc in the wrong way?

Reply With Quote
  #2  
Old April 12th, 2007, 05:58 PM
wiesemann wiesemann is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 153 wiesemann User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 h 29 m 35 sec
Reputation Power: 2
RE: MDB2 loadmodule extended

I'm too lazy to check whether getAssoc() is a method of the extended module, but I guess so. Your way of using getAssoc() should work on PHP 5. On PHP 4, you need to write $mdb2->extended->getAssoc($sql);

Reply With Quote
  #3  
Old April 12th, 2007, 06:35 PM
wputler wputler is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 2 wputler User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: MDB2 loadmodule extended

THANK YOU!! I hadn't found that reference anywhere!

I changed the code to:
php Code:
Original - php Code
  1.  
  2. $sql = 'SELECT category_id, category FROM nrg_categories ORDER BY category';
  3. $arr_categories = & $mdb2->extended->getAssoc($sql);


And it works! I did have to add another field - it requires 2 (duh - because it wants to return an associative array).

Reply With Quote
  #4  
Old April 12th, 2007, 06:37 PM
wiesemann wiesemann is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 153 wiesemann User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 h 29 m 35 sec
Reputation Power: 2
RE: MDB2 loadmodule extended

Nice to hear that it works now.

If the "->extended" thing isn't mentioned in the manual, then please report a bug.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPEAR Packages > MDB2 loadmodule extended


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
Stay green...Green IT