简体   繁体   English

错误fetchAll(PDO :: FETCH_ASSOC)

[英]Error fetchAll(PDO::FETCH_ASSOC)

I am implementing a research product of PDO and came across the following problem: when the sql query returns too many results, the process is stopped (white screen) after running the fetchAll (PDO :: FETCH_ASSOC). 我正在实施PDO的研究产品,遇到了以下问题:当sql查询返回太多结果时,运行fetchAll(PDO :: FETCH_ASSOC)后,进程将停止(白屏)。

-) The query was basically SELECT * FROM product WHERE .... (returns 3000) -)查询基本上是SELECT * FROM product WHERE .... (返回3000)

After a few tries changing the query to: 经过几次尝试,将查询更改为:

-) SELECT id, name FROM product WHERE .... -) SELECT id, name FROM product WHERE ....

The research work in all cases again. 在所有情况下,研究工作都会再次进行。

Just to clarify the query was always correct because the execute () method returned true. 只是为了澄清查询始终是正确的,因为execute()方法返回true。 The products table has about 60 columns including some kind of text that allow HTML content. 产品表大约有60列,其中包括允许HTML内容的某种文本。

I do not have much experience with PDO, unable to resolve the emergency problem but would like to know what was the reason of the problem. 我在PDO方面经验不足,无法解决紧急问题,但想知道问题的原因是什么。

Doubt: 怀疑:

Are there any limitations as to this PDO? 此PDO有任何限制吗? Maybe PHP to transform into array? 也许PHP可以转换为数组? WORKAROUND error? 解决方法错误? Thanks in advance, 提前致谢,

$STH = $DBH->query('SELECT field1,field2 from db'); 
setFetchMode(PDO::FETCH_ASSOC);

Just call only the fields you need so it execute fast. 只需仅调用所需的字段,即可快速执行。

If using SELECT * FROM.... means it get all columns.... so it takes more time to execute your query. 如果使用SELECT * FROM....意味着它将获取所有列....,因此需要更多时间来执行查询。

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

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