Small PDO problem

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
This is probably something that's really easy to solve, but I just can't
figure it out.

I have a "settings" table, of the following structure:

CREATE TABLE `settings` (
   `id` int(10) NOT NULL auto_increment,
   `name` varchar(255) default NULL,
   `value` varchar(255) default NULL,
   PRIMARY KEY  (`id`),
   UNIQUE KEY `index` (`name`)

I am fetching everything from it with the following code:

$q = $this->h->query("SELECT name,value FROM settings");
return $q->fetchAll();

The thing is, the returned array goes in the format of $data[0]. I want
it to be like $data['test_setting'] (by the "name" column). How do I
accomplish this? I am using PDO::FETCH_ASSOC as the fetch mode.


Re: Small PDO problem

Quoted text here. Click to load it

Euhm, RTFM?

return $q->fetchAll(PDO::FETCH_ASSOC);


Re: Small PDO problem

Rik Wasmus wrote:
Quoted text here. Click to load it

I said I am already using PDO::FETCH_ASSOC, being set earlier with
setAttribute(); It is not working, as you can see.

Re: Small PDO problem

Sweetiecakes wrote:
Quoted text here. Click to load it

You never showed that code.

And are you positive it never got changed?  Did you check it?  Did you
try Rik's code?  He's one of the most knowledgeable people here.

Or are you just going to argue?

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Site Timeline