3

更新似乎是 mysql 的一个问题,因为它也会从命令行截断它

无论如何,我工作中的数据库管理员想通了..看看我的解决方案

在 PHP(PDO、php_mysql 和 php_mysqli 都经过测试)中,我有一个使用 group_concat 的查询。当它被排序时,该字段中的数据被截断。

查询是相同的,除了在第二个中我已经注释掉了 order by 语句。我添加了 where 子句,因此它只会获取几条记录。有趣的是,如果您选择 EXACTLY 一个带有 order by 语句的记录,如 ID = 130...但如果您选择它作为一个范围,它会截断它 ID < 131 和 ID > 129

该示例使用 PDO,尽管我使用什么驱动程序似乎并不重要

注意:我尝试 CAST as char(1000) 但这不起作用

这是我的示例代码和输出

<?php
define('AREA','');
include ("phoenix/includes/config.php");
$config =& PhoenixConfig::get_instance();
$conn=$config->dbh;  //a PDO connection

$truncated="SELECT
  `ac_Export`.`ID` AS 'db-ac_Export-ID',
  `ac_Export`.`RunDate` AS 'db-ac_Export-RunDate',
  `ac_Export`.`Result` AS 'db-ac_Export-Result',
  `ac_Export`.`LogFile` AS 'db-ac_Export-LogFile',
  `ac_Export`.`Type` AS 'db-ac_Export-Type',
  `ac_Export`.`cscart_users_ID` AS 'db-ac_Export-cscart_users_ID',
  `ac_Export`.`cscart_user_name` AS 'db-ac_Export-cscart_user_name',
  GROUP_CONCAT(
    ac_Batch.BatchCode
    ORDER BY ac_Batch.BatchCode SEPARATOR ', '
  ) AS 'db-ac_Export-AllIncludedBatches'
FROM
  ac_Export
  LEFT JOIN ac_ExportBatch
    ON ac_Export.ID = ac_ExportBatch.ac_Export_ID 
  LEFT JOIN ac_Batch
    ON ac_ExportBatch.ac_Batch_ID = ac_Batch.ID

    where ac_Export.ID < 131 and ac_Export.ID > 129

GROUP BY ac_Export.ID
ORDER BY `db-ac_Export-RunDate` DESC
LIMIT 0,100 ";

echo "<h3>Truncated</h3>";


    $sql = $truncated;
    foreach ($conn->query($sql) as $row) {
        if ($row['db-ac_Export-ID']==130)
        {
            echo $row["db-ac_Export-AllIncludedBatches"];
            echo "<br>";
        }
    }



  $sql="SELECT
  `ac_Export`.`ID` AS 'db-ac_Export-ID',
  `ac_Export`.`RunDate` AS 'db-ac_Export-RunDate',
  `ac_Export`.`Result` AS 'db-ac_Export-Result',
  `ac_Export`.`LogFile` AS 'db-ac_Export-LogFile',
  `ac_Export`.`Type` AS 'db-ac_Export-Type',
  `ac_Export`.`cscart_users_ID` AS 'db-ac_Export-cscart_users_ID',
  `ac_Export`.`cscart_user_name` AS 'db-ac_Export-cscart_user_name',
  CAST(GROUP_CONCAT(
    ac_Batch.BatchCode
    ORDER BY ac_Batch.BatchCode SEPARATOR ', '
  ) AS CHAR(1000)) AS 'db-ac_Export-AllIncludedBatches'
FROM
  ac_Export
  LEFT JOIN ac_ExportBatch
    ON ac_Export.ID = ac_ExportBatch.ac_Export_ID
  LEFT JOIN ac_Batch
    ON ac_ExportBatch.ac_Batch_ID = ac_Batch.ID
WHERE ac_Export.ID < 131 and ac_Export.ID > 129
GROUP BY ac_Export.ID
/*ORDER BY `db-ac_Export-RunDate` DESC */
LIMIT 0, 100 ";
echo "<h3>Not Truncated</h3>";
    foreach ($conn->query($sql) as $row)
    {
        echo $row["db-ac_Export-AllIncludedBatches"];
    }

?>

输出示例:

截断

G2013050301, G2013050702, G2013052901, G2013053103, G2013060500, P2013050103, P2013050201, P2013050301, P2013050702, P2013050802, P2013050901, P2013051101, P2013051200, P2013051301, P2013051401, P2013051501, P2013051601, P2013051701, P2013052102, P2013052201, P2013052301, P2013052600, P2013052700, P2013052801, P2013052901, P2013053001, P20

未截断

G2013050301, G2013050702, G2013052901, G2013053103, G2013060500, P2013050103, P2013050201, P2013050301, P2013050702, P2013050802, P2013050901, P2013051101, P2013051200, P2013051301, P2013051401, P2013051501, P2013051601, P2013051701, P2013052102, P2013052201, P2013052301, P2013052600, P2013052700, P2013052801, P2013052901, P2013053001、P2013053102、P2013060500

4

1 回答 1

0

好的,所以我工作的数据库管理员发现此设置将解决问题

SET group_concat_max_len=4096;

这真的不能解释为什么订购该字段会影响它,但它现在似乎确实有效。

你可以设置

group_concat_max_len=<size you want>M

在你的

我的.cnf/我的.ini

于 2013-06-13T18:24:44.857 回答