SQLite3::query() - sqlite3数据库类
SQLite3::query()
(PHP 5 >= 5.3.0, PHP 7)
Executes an SQL query
说明
publicSQLite3::query(string $query): SQLite3ResultExecutes an SQL query, returning an SQLite3Result object. If the query does not yield a result(such as DML statements)the returned SQLite3Result object is not really usable. Use SQLite3::exec() for such queries instead.
参数
$queryThe SQL query to execute.
返回值
Returns an SQLite3Result object,或者在失败时返回FALSE
.
范例
SQLite3::query()example
The recommended way to do a SQLite3 query is to use a statement. For a table creation, a query might be fine (and easier) but for an insert, update or select, you should really use a statement, it's really easier and safer as SQLite will escape your parameters according to their type. SQLite will also use less memory than if you created the whole query by yourself. Example: You can also re-use a statement and change its parameters, just do $statement->reset(). Finally don't forget to close a statement when you don't need it anymore as it will free some memory.
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.
内容声明:本文中引用的各种信息及资料(包括但不限于文字、数据、图表及超链接等)均来源于该信息及资料的相关主体(包括但不限于公司、媒体、协会等机构)的官方网站或公开发表的信息。部分内容参考包括:(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供参考使用,不准确地方联系删除处理!本站为非盈利性质站点,本着为中国教育事业出一份力,发布内容不收取任何费用也不接任何广告!)