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:
<?php
$db = new SQLite3;
$statement = $db->prepare('SELECT * FROM table WHERE id = :id;');
$statement->bindValue(':id', $id);
$result = $statement->execute();
?>
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.
PHP.mk документација
SQLite3::query
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
Патека
sqlite3.query.php
Локална патека за оваа страница.
Извор
php.net/manual/en
Оригиналниот HTML се реупотребува и локално се стилизира.
Режим
Прокси + превод во позадина
Кодовите, табелите и белешките остануваат читливи во истиот тек.
Референца
sqlite3.query.php
SQLite3::query
Референца за `sqlite3.query.php` со подобрена типографија и навигација.
SQLite3::query
(PHP 5 >= 5.3.0, PHP 7, PHP 8)
SQLite3::query — Executes an SQL query
= NULL
Executes 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 ако прашањето успеало, for such queries instead.
Параметри
query-
за да го идентификувате кое поврзување сакате да го користите.
Вратени вредности
Враќа SQLite3Result објект, или false при неуспех.
Примери
Пример #1 SQLite3::query() example
<?php
$db = new SQLite3('mysqlitedb.db');
$results = $db->query('SELECT bar FROM foo');
while ($row = $results->fetchArray()) {
var_dump($row);
}
?>Белешки од корисници 2 забелешки
bohwaz ¶
пред 13 години
paule-panke at example dot com ¶
пред 9 години
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.