gpt4 book ai didi

PHP+SQLite sqlite_exec 和 sqlite_query 对比 mysql_query

转载 作者:搜寻专家 更新时间:2023-10-31 21:18:58 26 4
gpt4 key购买 nike

我知道 sqlite_exec 用于不返回结果集的查询,而 sqlite_query 用于返回结果集的查询。

但是,我可以像 mysql_query 一样使用 sqlite_query 进行各种查询吗?这有什么副作用吗?

最佳答案

sqlite_query

sqlite_query() returns a buffered, seekable result handle. This is useful for reasonably small queries where you need to be able to randomly access the rows. Buffered result handles will allocate memory to hold the entire result and will not return until it has been fetched. If you only need sequential access to the data, it is recommended that you use the much higher performance sqlite_unbuffered_query() instead.

sqlite_exec

This function will return a boolean result; TRUE for success or FALSE for failure. If you need to run a query that returns rows, see sqlite_query().

我认为始终使用 sqlite_query 之间不会有太大区别,尽管在 sqlite_query 确定没有结果时您可能会丢失一些时钟周期。这两个函数在失败时都返回 FALSE,因此只要您始终检查 FALSE 而不是 TRUE,您就可以摆脱它。

如果您正在做简单的 PHP 数据库工作,您可能还想看看 sqlite_unbuffered_query,按顺序迭代查询的结果。

我为此检查了 C API,它没有给出任何使用一个函数优于另一个函数的性能损失的迹象。

关于PHP+SQLite sqlite_exec 和 sqlite_query 对比 mysql_query,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1997447/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com