SQLite3::querySingle
(PHP 5 >= 5.3.0)
SQLite3::querySingle — Executes a query and returns a single result
Description
Executes a query and returns a single result.
Parameters
-
query
-
The SQL query to execute.
-
entire_row
-
By default, querySingle() returns the value of the first column returned by the query. If
entire_row
isTRUE
, then it returns an array of the entire first row.
Return Values
Returns the value of the first column of results or an array of the entire
first row (if entire_row
is TRUE
).
If the query is valid but no results are returned, then NULL
will be
returned if entire_row
is FALSE
, otherwise an
empty array is returned.
Invalid or failing queries will return FALSE
.
Examples
Example #1 SQLite3::querySingle() example
<?php
$db = new SQLite3('mysqlitedb.db');
var_dump($db->querySingle('SELECT username FROM user WHERE userid=1'));
print_r($db->querySingle('SELECT username, email FROM user WHERE userid=1', true));
?>
The above example will output something similar to:
string(5) "Scott" Array ( [username] => Scott [email] => scott@example.com )
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения для работы с базами данных
- Расширения для работы с базами данных отдельных производителей
- SQLite3
- Функция SQLite3::busyTimeout() - Sets the busy connection handler
- SQLite3::changes
- Функция SQLite3::close() - Closes the database connection
- Функция SQLite3::__construct() - Instantiates an SQLite3 object and opens an SQLite 3 database
- Функция SQLite3::createAggregate() - Registers a PHP function for use as an SQL aggregate function
- Функция SQLite3::createCollation() - Registers a PHP function for use as an SQL collating function
- Функция SQLite3::createFunction() - Registers a PHP function for use as an SQL scalar function
- SQLite3::enableExceptions
- Функция SQLite3::escapeString() - Returns a string that has been properly escaped
- Функция SQLite3::exec() - Executes a result-less query against a given database
- Функция SQLite3::lastErrorCode() - Returns the numeric result code of the most recent failed SQLite request
- Функция SQLite3::lastErrorMsg() - Returns English text describing the most recent failed SQLite request
- Функция SQLite3::lastInsertRowID() - Returns the row ID of the most recent INSERT into the database
- Функция SQLite3::loadExtension() - Attempts to load an SQLite extension library
- Функция SQLite3::open() - Opens an SQLite database
- SQLite3::openBlob
- Функция SQLite3::prepare() - Подготавливает SQL-запрос для выполнения
- Функция SQLite3::query() - Выполняет SQL-запрос
- Функция SQLite3::querySingle() - Executes a query and returns a single result
- Функция SQLite3::version() - Returns the SQLite3 library version as a string constant and as a number
Коментарии
RU
Какой смысл в этой функции? Ведь можно же и обычным query выбрать 1 строку или 1 ячейку. Почему тогда аналогичной функции нет для MySQL? Или тут какие-то особенности в реализации SQLite?
EN (google translate)
What is the use of this function? Fact can also use function «query» for select one row or one field. Why then no similar function for MySQL? Or are there any features in realization SQLite?