Skip to content

[RFC]: Sql Statement Query Caching #112

Open

Description

@simon-mundy

Proposed Version

0.6.0

Basic Information

PhpDb manually compiles each Select query for every single query, creating unnecessary overhead when a query itself will not change based on adapter/platform.

The intention of this proposal is to allow a caching mechanism which would determine if a Statement uses a Parameter Container and if so, store the compiled query in a cache that is user-determined. This still allows the database driver to correctly quote/execute data without needing to cache-bust regularly.

Background

No response

Considerations

No response

Proposal(s)

Sample pseudo code:-

$select->from('foo')->where([
    'c1' => null,
    'c2' => [1, 2, 3],
    new \Laminas\Db\Sql\Predicate\IsNotNull('c3'),
]);
// Cached string is 'SELECT "foo".* FROM "foo" WHERE "c1" IS NULL AND "c2" IN (?, ?, ?) AND "c3" IS NOT NULL'

$statement = $sql->prepareStatementForSqlObject($select, $storage); // where $storage is a PSR-6 compliant storage wrapper
$results = $statement->execute(); // Statement will use pre-prepared SQL string based on driver/adapter/platform

Appendix/Additional Info

No response

Activity

  1. added this to the 1.0.0 milestone on Jan 9, 2026
  2. self-assigned this
    on Jan 9, 2026
  3. added
    enhancementNew feature or request
    qaImprovements in quality assurance of the project
    on Jan 9, 2026
  4. tyrsson commented on Jan 26, 2026

    @tyrsson
    Member

    PhpDb should be able to consume any PSR compliant cache that is registered in a container.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Lang Feature RefactorRefactoring to new language featuresenhancementNew feature or requestqaImprovements in quality assurance of the project

Projects

  • Status
    Todo

Relationships

None yet

Development

No branches or pull requests

Issue actions