You can request rows from the database using SQL statements and format the output using these methods.
row( $sql )
Request a single row.
$user = $sqli->row('SELECT * FROM users');
{
"id": "1",
"firstName": "Hans",
"lastName": "Gruber",
"email": "hans@gruber.com"
}
list( $sql )
Request multiple rows.
$users = $sqli->list('SELECT * FROM users');
[
{
"id": "1",
"firstName": "Hans",
"lastName": "Gruber",
"email": "hans@gruber.com"
},
{
"id": "2",
"firstName": "Lars",
"lastName": "Ulrich",
"email": "lars@metal.com"
},
{
"id": "3",
"firstName": "Hans",
"lastName": "Nickerdorph",
"email": "hans@nick.com"
}
]
listId( $sql [, $key = 'id' ] )
Request multiple rows indexed by key value. The default key is id
.
$users = $sqli->listId('SELECT * FROM users LIMIT 2');
A specific key can also be supplied.
$users = $sqli->listId('SELECT * FROM users LIMIT 2', 'email');
{
"hans@gruber.com": {
"id": "1",
"firstName": "Hans",
"lastName": "Gruber",
"email": "hans@gruber.com"
},
"lars@metal.com": {
"id": "2",
"firstName": "Lars",
"lastName": "Ulrich",
"email": "lars@metal.com"
}
}
groupId( $sql [, $key = 'id' ] )
Request multiple rows indexed by key value. The default key is id
.
$users = $sqli->groupId('SELECT * FROM users');
A specific key can also be supplied.
$users = $sqli->groupId('SELECT * FROM users', 'firstName');
{
"Hans": [
{
"id": "1",
"firstName": "Hans",
"lastName": "Gruber",
"email": "hans@gruber.com"
},
{
"id": "3",
"firstName": "Hans",
"lastName": "Nickerdorph",
"email": "hans@nick.com"
}
],
"Lars": [
{
"id": "2",
"firstName": "Lars",
"lastName": "Ulrich",
"email": "lars@metal.com"
}
]
}
keys( $sql )
Request the keys contained in the query.
$user = $sqli->keys('SELECT * FROM users');
[
"id",
"firstName",
"lastName",
"email"
]
values( $sql )
Request only the values of the first row in the query.
$user = $sqli->values('SELECT * FROM users');
[
"1",
"Hans",
"Gruber",
"hans@gruber.com"
]
Last updated