Sqlite3 和 PDO 与 ORDER BY 的问题
我尝试
SELECT * FROM table ORDER BY column
通过 PHP 中的 PDO 对象使用 SQL 语句。问题是,当使用除 ID 之外的所有列名的名称时,我总是收到错误(在非对象上调用成员函数 fetchall() - 这意味着查询没有返回 PDO 对象)。当我查询
SELECT * FROM table ORDER BY ID
它的工作原理时。 ID 是 PRIMARY INTEGER KEY,所有其他列都是 TEXT 或 NUMERIC,它们都不适用于 ORDER BY 子句。
有什么想法吗?
I try to use the SQL statement
SELECT * FROM table ORDER BY column
via an PDO-Object in PHP. Problem is, that I always get an error (Call to a member function fetchall() on a non-object - that means, the query did not return a PDO-object) when using the names of all columnname EXCEPT for ID. When I query
SELECT * FROM table ORDER BY ID
it works. ID is the PRIMARY INTEGER KEY, all other columns are TEXT or NUMERIC, neither of them would works with the ORDER BY clause.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如您在对 Frank Heikens 的回答的评论中所建议的那样,这可能是临时文件的问题。
http://www.sqlite.org/tempfiles.html 说:
是否创建文件以及创建位置由
SQLITE_TEMP_STORE
、PRAGMA temp_store
和PRAGMA temp_store_directory
控制,请参阅 http://www.sqlite.org/pragma.htmlIt could be an issue with temporary files as you've suggested in your comment to Frank Heikens's answer.
http://www.sqlite.org/tempfiles.html says:
If and where files are created is controlled by
SQLITE_TEMP_STORE
,PRAGMA temp_store
andPRAGMA temp_store_directory
, see http://www.sqlite.org/pragma.html将您的
ORDER BY
语句替换为按演员排序(列为真实)
。它可以对 REAL 值进行排序。
Replace your
ORDER BY
statement withORDER BY CAST(COLUMN AS REAL)
.It can sort
REAL
values.