SQLite3::querySingle

(PHP 5 >= 5.3.0, PHP 7)

SQLite3::querySingleExecutes a query and returns a single result

说明

public SQLite3::querySingle ( string $query [, bool $entire_row = FALSE ] ) : mixed

Executes a query and returns a single result.

参数

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 is TRUE, then it returns an array of the entire first row.

返回值

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.

范例

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));
?>

以上例程的输出类似于:

string(5) "Scott"
Array
(
    [username] => Scott
    [email] => scott@example.com
)

相关文章
php ibm db2 函数 returns a single column from a row in the result setphp mysqlnd ms 函数 returns query distribution and connection statisticsphp sqlite 函数 execute a query against a given database and returns an arrayphp sqlite 函数 executes a result less query against a given databasephp sqlite 函数 returns the number of fields in a result setphp sqlite 函数 returns the number of rows in a buffered result setphp sqlite 函数 executes a query against a given database and returns a result handlephp sqlite 函数 executes a query and returns either an array for one single column or the value of the first rowphp sdo das relational 函数 executes a given sql query against a relational database and returns the results as a normalised data graphphp solrquery returns the maximum number of query terms that will be included in any generated queryphp solrquery returns whether or not to include the lower bound in the result setphp sqlite3 executes a result less query against a given databasephp sqlite3 returns the numeric result code of the most recent failed sqlite requestphp sqlite3 executes an sql queryphp sqlite3 executes a query and returns a single resultphp sqlite3result returns the name of the nth columnphp sqlite3result returns the type of the nth columnphp sqlite3result fetches a result row as an associative or numerically indexed array or bothphp sqlite3result returns the number of columns in the result setphp sqlite3stmt executes a prepared statement and returns a result set object
关注编程学问公众号