Repository navigation
Parameter binding
Greg Bowler edited this page Mar 3, 2026
·
5 revisions
Here, we will look at all binding styles supported by PHP.Gt/Database.
select * from user where id = ?$user = $db->fetch("user/getById", 42);select * from user where email = :email and isActive = :isActive$user = $db->fetch("user/getByEmail", [
"email" => "dev@example.com",
"isActive" => true,
]);Bindings are flattened, so the following are equivalent:
$db->fetch("user/getByEmail", ["email" => "a@example.com", "isActive" => 1]);
$db->fetch("user/getByEmail", ["email" => "a@example.com"], ["isActive" => 1]);
$db->fetch("user/getByEmail", [["email" => "a@example.com"], ["isActive" => 1]]);-
boolbecomes0or1 -
DateTimeInterfacebecomesY-m-d H:i:s - arrays are expanded to indexed placeholders such as
:ids__0,:ids__1
These values are injected into SQL after sanitisation:
:groupBy:orderBy:limit:offset:infileName
Example:
select id, email from user
order by :orderBy
limit :limit offset :offset$rows = $db->fetchAll("user/list", [
"orderBy" => "id desc",
"limit" => 20,
"offset" => 40,
]);-
:__dynamicValueSetfor generated multi-row insert value sets -
:__dynamicInfor runtimeIN (...)content -
:__dynamicOrfor groupedORconditions
Now we can build flexible query templates without manual string concatenation in application logic.
Example code: example/04-dynamic-bindings.php
PHP.GT/Database is a separately maintained component used by PHP.GT/WebEngine.