更新似乎是一个带有mysql的问题,因为它也会从命令行截断它
不管怎样,我工作的一个数据库管理员发现了…看我的解决方案
在php(pdo、php_mysql和php_mysql i都经过测试)中,我有一个使用group_concat的查询。排序后,该字段中的数据将被截断。
除了在第二个查询中我注释掉了order by语句之外,其他查询都是相同的。我添加了where子句,这样它只能获取一些记录。有趣的是,如果您使用order by语句(如id=130)只选择一条记录,数据将不会被截断…但是如果你选择它作为一个范围,它会截断id129
这个例子使用pdo,尽管我使用的驱动程序似乎并不重要
注意:我试过用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

最佳答案

好的,所以我工作的一个数据库管理员发现这个设置可以解决这个问题
设置组_concat_max_len=4096;
这并不能解释为什么订购字段会对它产生影响,但它现在似乎确实起作用了。
你可以设定

group_concat_max_len=<size you want>M

在你的
我的.cnf/我的.ini

关于php - 在PHP中订购时,mysql字段值被截断,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17093087/

10-13 03:19