Small PDO problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sweetiecakes

    Small PDO problem

    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("SELEC T 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_ASSO C as the fetch mode.

    Thanks
  • Rik Wasmus

    #2
    Re: Small PDO problem

    On Fri, 31 Oct 2008 21:22:03 +0100, Sweetiecakes <x@x.comwrote :
    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("SELEC T 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_ASSO C as the fetch mode.
    Euhm, RTFM?



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

    --
    Rik

    Comment

    • Sweetiecakes

      #3
      Re: Small PDO problem

      Rik Wasmus wrote:
      On Fri, 31 Oct 2008 21:22:03 +0100, Sweetiecakes <x@x.comwrote :
      >
      Euhm, RTFM?
      >

      >
      return $q->fetchAll(PDO:: FETCH_ASSOC);
      >
      I said I am already using PDO::FETCH_ASSO C, being set earlier with
      setAttribute(); It is not working, as you can see.

      Comment

      • Jerry Stuckle

        #4
        Re: Small PDO problem

        Sweetiecakes wrote:
        Rik Wasmus wrote:
        >On Fri, 31 Oct 2008 21:22:03 +0100, Sweetiecakes <x@x.comwrote :
        >>
        >Euhm, RTFM?
        >>
        >http://nl2.php.net/PDO_statment_fetch_all
        >>
        >return $q->fetchAll(PDO:: FETCH_ASSOC);
        >>
        >
        I said I am already using PDO::FETCH_ASSO C, being set earlier with
        setAttribute(); It is not working, as you can see.
        >
        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.
        jstucklex@attgl obal.net
        =============== ===

        Comment

        Working...