简体   繁体   English

DESC的MySQL命令挂起; ASC很好

[英]MySQL order by DESC hangs; ASC is fine

I have a simple MySQL database table with just 20 records. 我有一个只有20条记录的简单MySQL数据库表。 The ID column is an AUTO_INCREMENT integer which is set as the primary key. ID列是一个AUTO_INCREMENT integer ,它被设置为主键。

This code is trying to fetch the most recent entry from the table, using a PDO object: 这段代码试图使用PDO对象从表中获取最新条目:

$query="SELECT * FROM latest_news ORDER BY ID ASC";

$pdo=connectToDatabase();
$result=$pdo->query($query);

$newsStory=$result->fetch();

This code works fine when I'm sorting ascending ORDER BY ID ASC , but when I sort descending ORDER BY ID DESC , it hangs and loses connection. 当我按ORDER BY ID ASC升序对ORDER BY ID ASC排序时,此代码可以正常工作,但是当按ORDER BY ID DESC降序对ORDER BY ID DESC排序时,它会挂起并失去连接。 No PHP error message is displayed; 没有显示PHP错误消息; the page never loads in the browser, even after a long wait. 即使长时间等待,该页面也永远不会加载到浏览器中。

Environment is PHP 5.4.45, MySQL 5.6.27 and a local web server using EasyPHP 14.1 环境是PHP 5.4.45,MySQL 5.6.27和使用EasyPHP 14.1的本地Web服务器

Of course, if any more information is needed, please let me know. 当然,如果需要更多信息,请告诉我。 Still fairly new to MySQL queries. 对于MySQL查询来说还是相当新的。

This turned out to be due to the result of the MySQL query. 事实证明这是由于MySQL查询的结果。

When using DESC , the result was huge, and being processed by another function caused PHP to hang. 当使用DESC ,结果是巨大的,并且被另一个函数处理导致PHP挂起。

The result from ASC was different and smaller, so was not causing the same problem. ASC结果不同且较小,因此不会引起相同的问题。

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

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