Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-31-2008, 02:54 PM
Junior Member
 
Join Date: Mar 2008
Posts: 3
Cool Fetching only some fields in Zend_Db_Table

As a rule, I like to use Zend_Db_Table for my database work. It's a nice, abstracted layer that keeps me from having to mess with SQL.

It's got a couple drawbacks, and one of them is that it fetches every column every time, which makes every DBA I work with grind their teeth. I'd like a method that limits the query to only columns I need. The result of the query would be limited Zend_Db_Table_Row objects (or a rowset of them) that would only give information on some columns and maybe couldn't be saved.

So is there a method to limit columns on Zend_Table_Row fetches and I just haven't figured out what it is? Has anyone already written such a method? Would anyone like to have it if I write such a method myself?

I imagine someone will say, "Well, if you only want to query a couple columns, why don't you use a different method?" I believe that, in an environment with several coders, it's better to keep the database API consistent. If a set of developers who don't know Zend_Framework find they have to learn Zend_Db_Tables to fetch and create records and then have to learn to do raw selects to fetch limited records, sooner or later, some of them might get frustrated and start sending all their queries to the adapter.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-31-2008, 10:05 PM
Junior Member
 
Join Date: Mar 2008
Posts: 3
Default

I thought you can filter only the columns you want in your sql statement.

I try $db->fetchAll('SELECT col1, col2 FROM table WHERE condition LIMIT n, m');
I got an associative array.

I guess the default fetch mode is FETCH_ASSOC.

Don't worry if you don't know what I am talking about. I only play with the Zend Framework for 3 days and haven't play with any other PHP framework. If the way I am doing is wrong please let me know.

Hopefully, I answer your question.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-01-2008, 09:40 PM
Junior Member
 
Join Date: Mar 2008
Posts: 5
Default

You can use the Zend_Db_Table_Select object to do this. The documentation has some examples of how this works:

Zend Framework: Documentation - Zend_Db_Table advanced usage
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 05:03 AM.