Zend_Db issue with fetchAssoc

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Zend_Db issue with fetchAssoc

Post by alex.barylski »

I have the following code:

Code: Select all

//$this->db->setFetchMode(Zend_Db::FETCH_OBJ);
$results = $this->db->fetchAssoc('SELECT * FROM sites WHERE id = ?', 1);
 
I am getting the following results:

Code: Select all

Array
(
    [1] => Array
        (
            [id] => 1
            [name] => default shop
            [description] => Default shop.
            [base_url] => http://localhost/
            [warehouse_filters_enabled] => 0
            [category_filters_enabled] => 0
            [view_directory] => default
            [app_folder] => shop_main
            [session_name] => shopmain
            [is_down] => 0
            [down_time_msg] => 
            [enable_cutomer_category_filters] => 1
        )
 
)
 
The error here (if not obvious) is that I am selecting a single record and should be able to return the details like:

Code: Select all

return $results[0];
Which I cannot do because the index is ONE???

What am I doing wrong?

Cheers,
Alex
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Zend_Db issue with fetchAssoc

Post by John Cartwright »

The index is the primary key, so you'll either need to handle the logic in your model (array_shift() or alike) to use the fetchRow() method.
Post Reply