##sql語句為```SELECT COUNT(id) AS tp_count FROM `tableName` WHERE `status` = 0 AND `source` = 1 AND ( `end_time`-`add_time` > 2592000 AND `end_time`-`add... ...
sql語句為
SELECT
COUNT(id) AS tp_count
FROM
`tableName`
WHERE
`status` = 0
AND `source` = 1
AND (
`end_time`-`add_time` > 2592000
AND `end_time`-`add_time` <= 5184000
) LIMIT 1
發生報錯如下
PDOException:SQLSTATE [HY000]:常規錯誤:2014在其他未緩衝的查詢處於活動狀態時無法執行查詢。
考慮使用PDOStatement :: fetchAll()。
或者,如果您的代碼只是針對mysql運行,則可以通過設置PDO :: MYSQL_ATTR_USE_BUFFERED_QUERY屬性來啟用查詢緩衝。
在google查找報錯信息,各種改配置,優化 sql,沒有明確辦法
在阿裡雲 SDN上執行 sql,發現報錯
Data truncation: BIGINT UNSIGNED value is out of range in '(`end_time`-`add_time` > 2592000
AND `end_time`-`add_time` <= 5184000
)'
經過排查發現,有的數據中end_time小於 add_time,所以 sql 條件運算為負值,產生 BIGINT UNSIGNED 報警,於是修改 sql 如下
SELECT
COUNT(id) AS tp_count
FROM
`tableName`
WHERE
`status` = 0
AND `source` = 1
AND `end_time` > `add_time`
AND (
`end_time`-`add_time` > 2592000
AND `end_time`-`add_time` <= 5184000
) LIMIT 1