問題描述
我正在使用 PHP 函數(shù) mysqli_query
運行 SELECT
查詢.
I am using the PHP function mysqli_query
to run a SELECT
query.
如果查詢運行成功,但查詢沒有找到匹配項,mysqli_query
返回什么?
What does mysqli_query
return if the query runs successfully, but the query finds no matches?
推薦答案
根據(jù) 手冊:
失敗時返回 FALSE.對于成功的 SELECT、SHOW、DESCRIBE 或 EXPLAIN 查詢,mysqli_query() 將返回一個 mysqli_result 對象.對于其他成功的查詢,mysqli_query() 將返回 TRUE.
Returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object. For other successful queries mysqli_query() will return TRUE.
運行但不返回結(jié)果的查詢?nèi)员灰暈槌晒Σ樵?,因為該查詢確實在數(shù)據(jù)庫中運行并且空結(jié)果集是合法響應.這意味著查詢?nèi)匀粫祷匾粋€ mysqli_result
對象,如果你檢查它的行數(shù)(通過面向?qū)ο箫L格的 $result->num_rows
或 mysqli_num_rows($result)
在程序風格中)它將返回 0.
A query that runs but returns no results is still considered a "successful query", since the query did run in the database and an empty result set is a legitimate response. This means the query will still return a mysqli_result
object, and if you check its row count (either via $result->num_rows
in the object-oriented style or mysqli_num_rows($result)
in the procedural style) it will return 0.
這篇關(guān)于mysqli_query - 返回值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!