GROUP_CONCAT()mysql返回有限的字符

时间:2015-04-07 08:22:24

标签: php mysql group-concat

我有两张桌子

tblColorLibrary

id   name
1     test color

tblColors

id  libraryId  colorCode  name
1     1           #fff     Prime Color
2     1           #ddd     Secondry Color
3     1           #E2CFC7  Favorite Color

以下是我的询问:

$stmt ="SELECT a.id, a.isActive as isActive, a.name as title, GROUP_CONCAT(b.colorCode ) as colors, GROUP_CONCAT(b.name) as name FROM ".$this->tblLibrary." as a JOIN tblcolors as b ON a.id = b.libraryId GROUP BY a.id ORDER BY b.id ASC";

此查询将返回此结果

Array
(
    [0] => Array
        (
            [id] => 1
            [isActive] => Y
            [title] => test
            [colors] => #fff,#ddd,#E2CFC7
            [name] => Prime Color, Secondry Color, Favorite Color
        )

)

一切顺利,直到我的记录有限。当我在tblColors中有超过150条记录时,name key仅提供有限数量的字符。没有完整的记录。

我想群组会有限制。

2 个答案:

答案 0 :(得分:1)

在mysql数据库中增加group_concat_max_len。默认设置为1024.您可以使用查询

更新它
SET GLOBAL group_concat_max_len=100000

SET SESSION group_concat_max_len = 1000000;

答案 1 :(得分:1)

检查group_concat_max_len的值并根据需要增加它。

show variables like 'group_concat_max_len';