rawQueryOne()
The rawQueryOne()
method is a shortcut for executing a raw SQL query that returns a single row.
It works like rawQuery()
but automatically returns the first result only.
Signature:
public function rawQueryOne(string $query, ?array $bindParams = null): array|object|null
Basic Example
$sql = "SELECT * FROM test_users WHERE id = ?";
$user = $db->rawQueryOne($sql, [123]);
Return Value
- Returns a single row as array or object (depending on
setOutputMode()
) - Returns
null
if no result is found - Returns
false
on SQL error
Notes
- Use
rawQueryOne()
only when you expect exactly one result - Internally uses
LIMIT 1
if not already present - Always bind parameters via the second argument – do not concatenate raw values
Important:
Never insert
Always use parameter placeholders (
Never insert
$_POST
or other user input directly into your SQL query.Always use parameter placeholders (
?
) and bind values safely.