PDO fetchAll() primary key as array group key

后端 未结 6 897
南笙
南笙 2020-12-10 04:26

I want to store the contents of a specific database into an array, grouped by their primary keys. (Instead of the useless way PDO fetchAll() organises them).

My curr

6条回答
  •  眼角桃花
    2020-12-10 04:48

    I'd like to point out the only solution that works for me:

    fetchAll(\PDO::FETCH_GROUP|\PDO::FETCH_UNIQUE|\PDO::FETCH_ASSOC);

    Beware that this will strip the first column from the resultset. So the query must be:

    SELECT id_keyname AS arrkey, id_keyname, .... FROM ...

提交回复
热议问题