Page MenuHomeDevCentral

Fetch a scalar value from a result
ClosedPublic

Authored by dereckson on Nov 1 2025, 12:05.
Tags
None
Referenced Files
F57548523: D3838.id9934.diff
Fri, Nov 20, 05:26
F57369525: D3838.id9934.diff
Wed, Nov 18, 05:09
F56969378: D3838.diff
Thu, Nov 12, 01:48
F56736938: D3838.id9934.diff
Sun, Nov 8, 19:39
F56627210: D3838.id9935.diff
Sat, Nov 7, 19:37
F56338560: D3838.diff
Thu, Nov 5, 04:56
F56143280: D3838.id9934.diff
Tue, Nov 3, 07:51
F56143277: D3838.id9935.diff
Tue, Nov 3, 07:51
Subscribers
None

Details

Summary

While queryScalar is useful for fetching scalar values in queries like
SELECT count(*), it cannot be used with prepared statements in PDO.

DatabaseResult::fetchScalar returns the first item of the next row.

The following fluent pattern is now supported:

$sql = "SELECT count(*) FROM foo WHERE id = :id";

return $this->db
    ->prepare($sql)
    ->with("id", $this->id)
    ->query()
    ->fetchScalar();

fetchScalar is implemented at DatabaseResult level, making it available
with all drivers, not just PDO.

Ref T2169

Test Plan
  • New unit test for current Result tests classes
  • Tested with D3835 on Obsidian codebase

Diff Detail

Repository
rKERUALD Keruald libraries development repository
Lint
Lint Passed
Unit
Tests Passed
Branch
main
Build Status
Buildable 6130
Build 6414: arc lint + arc unit

Event Timeline

dereckson created this revision.
dereckson edited the test plan for this revision. (Show Details)
dereckson added a child revision: D3835: Read from Orbeon Forms.
This revision is now accepted and ready to land.Nov 1 2025, 12:09