简体   繁体   English

Group_concat或PDO :: FETCH_ASSOC

[英]Group_concat or PDO::FETCH_ASSOC

Basically I am trying to achieve the same as stated on the link below db field(GROUP_CONCAT) as array 基本上我正在尝试实现与db字段(GROUP_CONCAT)下的链接所声明的相同的数组

The reason why I am writing regarding similar question is because all the answers related to I can find related to group_concat that applies to my case are from 2011, 2012. So I am not sure if that is the best solution now days. 我之所以写类似的问题,是因为我能找到的所有与group_concat相关的答案都适用于我的案例,这些答案都来自2011年,2012年。所以我不确定这是否是当今最好的解决方案。

I have created so far this 到目前为止,我已经创建了

        $sql->select( array('a.id', 'a.user_id', 'a.title', 'a.created', 'a.published', 'b.title AS obtitle', 'b.items_id'))
        ->from($this->db->quoteName('table1', 'a'))
        ->join('LEFT', $this->db->quoteName('table2', 'b'). '
        ON (' .$this->db->quoteName('a.id').'='.$this->db->quoteName('b.items_id').')')
        ->where($this->db->quoteName('a.user_id') . ' =' . $this->db->quote($userid).' AND ' .$this->db->quoteName('a.published') . ' = 1')
        ->group($this->db->quoteName('b.item_id'));

        $query = $this->db->setQuery($sql);

My question, is it still right to use group_concat? 我的问题是,仍然可以使用group_concat吗? Or is it old practice (hence why I only find old answers)? 还是旧的做法(因此为什么我只能找到旧的答案)? would PDO::FETCH_ASSOC be more appropriate for merging the results that have a common id into an array and sub array? PDO :: FETCH_ASSOC是否更适合将具有公共ID的结果合并到数组和子数组中?

group_concat没什么错,但是PDO :: FETCH_ASSOC在分组任何内容方面都没有丝毫帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM