SQLite3Result::fetchArray() - sqlite3数据库类
SQLite3Result::fetchArray()
(PHP 5 >= 5.3.0, PHP 7)
Fetches a result row as an associative or numerically indexed array or both
说明
publicSQLite3Result::fetchArray([int $mode= SQLITE3_BOTH]): arrayFetches a result row as an associative or numerically indexed array or both. By default, fetches as both.
参数
$modeControls how the next row will be returned to the caller. This value must be one of eitherSQLITE3_ASSOC,SQLITE3_NUM, orSQLITE3_BOTH.
SQLITE3_ASSOC: returns an array indexed by column name as returned in the corresponding result set
SQLITE3_NUM: returns an array indexed by column number as returned in the corresponding result set, starting at column 0
SQLITE3_BOTH: returns an array indexed by both column name and number as returned in the corresponding result set, starting at column 0
返回值
Returns a result row as an associatively or numerically indexed array or both. Alternately will return FALSE
if there are no more rows.
The types of the values of the returned array are mapped from SQLite3 types as follows: integers are mapped to integer if they fit into the range PHP_INT_MIN
..PHP_INT_MAX
, and to string otherwise. Floats are mapped to float,NULLvalues are mapped to null, and strings and blobs are mapped to string.
Check with SQLite3Result::numColumns() for an empty result before calling SQLite3Result::fetchArray(). In contrast to the documentation SQLite3::query() always returns a SQLite3Result instance, not only for queries returning rows (SELECT, EXPLAIN). Each time SQLite3Result::fetchArray() is called on a result from a result-less query internally the query is executed again, which will most probably break your application. For a framwork or API it's not possible to know in before whether or not a query will return rows (SQLite3 supports multi-statement queries). Therefore the argument "Don't execute query('CREATE ...')" is not valid.
Would just like to point out for clarification that each call to fetchArray() returns the next result from SQLite3Result in an array, until there are no more results, whereupon the next fetchArray() call will return false. HOWEVER an additional call of fetchArray() at this point will reset back to the beginning of the result set and once again return the first result. This does not seem to explicitly documented, and caused me my own fair share of headaches for a while until I figured it out. For example:
鹏仔微信 15129739599 鹏仔QQ344225443 鹏仔前端 pjxi.com 共享博客 sharedbk.com
图片声明:本站部分配图来自网络。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!