Type safe getters
This library includes typed fetch helpers for queries that return one column, as well as typed getters on Row.
Single-value fetch helpers
If a query returns one value, we can ask for the PHP type directly:
fetchBool()fetchString()fetchInt()fetchFloat()fetchDateTime()
$username = $db->fetchString("user/getUsernameById", 105);
$score = $db->fetchFloat("score/calculateForUser", 8008);
$lastActivity = $db->fetchDateTime("user/getLatestActivity", 654);
That avoids the usual pattern of fetching a row and then reading the first field manually.
Multiple typed values
If the query still returns one column but many rows, there are matching helpers:
fetchAllBool()fetchAllString()fetchAllInt()fetchAllFloat()fetchAllDateTime()
$userIds = $db->fetchAllInt("user/getAllIds");
These methods exist on both Database and QueryCollection.
Typed access on Row
When we use fetch() or iterate over a ResultSet, each row provides:
getString()getInt()getFloat()getBool()getDateTime()get()
$user = $db->fetch("user/getById", 105);
if($user) {
echo $user->getString("email");
echo $user->getBool("isActive") ? "active" : "inactive";
}
Date and time values
getDateTime() and fetchDateTime() accept:
- normal database date strings such as
2026-02-01 00:05:00 - numeric Unix timestamps
That keeps the calling code consistent even when the underlying schema stores dates in different formats.
Plain arrays when we need them
If we need raw arrays instead of typed accessors:
$rowArray = $user->asArray();
$resultArray = $db->fetchAll("user/getAll")->asArray();
That is useful for debugging, serialisation, or handing the data to another layer that already expects arrays.
Next, move on to Multiple connections.