PHP Classes

Rasher PHP Data Access Layer Helper - Database Repository: Attribute-based PHP data access layer with repos

Recommend this page to a friend!
  Info   Screenshots   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2026-01-16 (3 hours ago) RSS 2.0 feedNot enough user ratingsTotal: 59 All time: 10,526 This week: 57Up
Version License PHP version Categories
data_access_helper 2.46MIT/X Consortium ...7.4Databases, User Management, Cache, Da..., D..., P..., T...
Description 

Author

This package provides several classes that can connect to many kinds of databases and executes SQL queries to perform any type of data access (MySQLi, PDO) to database tables.

Currently, it can:

- Connect to a database server via MySQLi or PDO extensions

- Execute prepared queries and get the results as an array or by result column name

- Access a database like a repository with functions to access repository records by performing operations to create, read, update, and delete repository items

- Manipulate database record column values according to the respective data type

- DT_ITEM, DT_LIST complex attribute types and searching abilities

- Transaction handling

- Caching the database query results

- Comparison operators to define filtering conditions

Picture of Hernádi Tamás
  Performance   Level  
Name: Hernádi Tamás <contact>
Classes: 1 package by
Country: Hungary Hungary
Age: 45
All time rank: 448440 in Hungary Hungary
Week rank: 195 Up3 in Hungary Hungary Up

Instructions

DataAccessLayerHelper

DBRepository

Rasher PHP Data Access Layer Helper & Database Repository

This package provides a flexible Data Access Layer (DAL) and Repository pattern implementation for PHP applications. It is designed to work with complex object graphs, in-memory caching, and recursive attribute-based filtering.

The primary goal is to access database records as structured objects instead of raw arrays, while supporting advanced filtering logic without querying the database repeatedly.

Key Features

Database Access

  • Connects to database servers using MySQLi or PDO
  • Supports multiple database engines (MySQL, MSSQL, etc.)
  • Executes prepared SQL queries
  • Fetches results as: - associative arrays - repository item objects - column-based result sets
  • Transaction handling (BEGIN / COMMIT / ROLLBACK)

Repository Pattern

  • Repository-style access to database tables
  • CRUD operations: - create - read - update - delete
  • Database rows are mapped to attribute-based objects
  • Strong separation between data access and business logic

Attribute System

Each repository item is built from attributes that describe: - name - data type - formatting - default value - visibility - read-only state

Supported attribute data types include:

  • Primitive types: `DT_STRING`, `DT_INT`, `DT_BOOL`, `DT_FLOAT`, `DT_DATETIME`, etc.
  • Complex types: - DT_ITEM – reference to a single related item - DT_LIST – collection of related items (always ends with `Collection`)

This allows building deep object graphs from relational data.

Recursive Filtering (find())

One of the core features of this library is the recursive, in-memory filtering engine.

  • Filters work on cached repository items
  • No additional database queries are executed
  • Filtering supports:
    - nested DT_ITEM &#8594; DT_LIST &#8594; DT_ITEM chains
    - attribute paths using dot notation  
      Example:
      UserRolesCollection.UserRole.UserRoleSettingsCollection.Value
    

Supported comparison operators:

  • `=`, `!=`
  • `<`, `<=`, `>`, `>=`
  • `LIKE`, `NOT LIKE`
  • `IS NULL`, `IS NOT NULL`

Logical operators:

  • `AND` (default)
  • `OR`

Filtering is context-aware: - When multiple conditions target the same collection, they must match within the same collection element - This avoids false-positive matches across unrelated list items

Caching

  • Repository results can be cached in memory
  • The `find()` method operates on cached objects
  • Significantly improves performance for repeated filtering
  • Ideal for: - authorization checks - configuration resolution - complex user-role-setting evaluations

Stored Procedures & Testing

  • Stored procedure execution (PDO, MSSQL)
  • Built-in test scripts for: - data generation - stored procedure execution - filtering validation

Minimum Requirements

  • PHP 7.4 or higher
  • Recommended: PHP 7.4 – 8.0
  • PHP 8.2+ is supported with minor adjustments (see `UPGRADE.md` for details)

Required PHP extensions: - mysqli or pdo - pdo_mysql / pdo_sqlsrv depending on database engine

Design Goals

  • Avoid repetitive database queries
  • Work with structured, typed data instead of raw arrays
  • Support complex domain models
  • Allow expressive filtering without SQL complexity
  • Keep business logic independent from database structure

Project Status

Implemented

  • Repository pattern
  • Attribute-based object mapping
  • Recursive filtering engine
  • DT_ITEM / DT_LIST support
  • Transaction handling
  • In-memory caching
  • Comparison operators
  • Stored procedure support

Planned (Later Development Phase)

  • Database table script generation from attribute definitions
  • Concurrent data management
  • Historical data handling (`DBHistoricalRepository`)
  • Extended documentation
  • Improved function and parameter descriptions

Notes

This library is intentionally not an ORM. It focuses on predictable behavior, explicit data structures, and fine-grained control over filtering and data traversal.

For PHP version upgrade notes, see UPGRADE.md.

Details

# DataAccessLayerHelper # DBRepository Rasher PHP Data Access Layer Helper & Database Repository This package provides a flexible **Data Access Layer (DAL)** and **Repository pattern implementation** for PHP applications. It is designed to work with complex object graphs, in-memory caching, and recursive attribute-based filtering. The primary goal is to access database records as structured objects instead of raw arrays, while supporting advanced filtering logic without querying the database repeatedly. --- ## Key Features ### Database Access - Connects to database servers using **MySQLi** or **PDO** - Supports multiple database engines (MySQL, MSSQL, etc.) - Executes prepared SQL queries - Fetches results as: - associative arrays - repository item objects - column-based result sets - Transaction handling (BEGIN / COMMIT / ROLLBACK) --- ### Repository Pattern - Repository-style access to database tables - CRUD operations: - create - read - update - delete - Database rows are mapped to **attribute-based objects** - Strong separation between data access and business logic --- ### Attribute System Each repository item is built from attributes that describe: - name - data type - formatting - default value - visibility - read-only state Supported attribute data types include: - Primitive types: `DT_STRING`, `DT_INT`, `DT_BOOL`, `DT_FLOAT`, `DT_DATETIME`, etc. - Complex types: - **DT_ITEM** ? reference to a single related item - **DT_LIST** ? collection of related items (always ends with `Collection`) This allows building **deep object graphs** from relational data. --- ### Recursive Filtering (`find()`) One of the core features of this library is the **recursive, in-memory filtering engine**. - Filters work on cached repository items - No additional database queries are executed - Filtering supports: - nested DT_ITEM ? DT_LIST ? DT_ITEM chains - attribute paths using dot notation Example: ``` UserRolesCollection.UserRole.UserRoleSettingsCollection.Value ``` #### Supported comparison operators: - `=`, `!=` - `<`, `<=`, `>`, `>=` - `LIKE`, `NOT LIKE` - `IS NULL`, `IS NOT NULL` #### Logical operators: - `AND` (default) - `OR` Filtering is **context-aware**: - When multiple conditions target the same collection, they must match **within the same collection element** - This avoids false-positive matches across unrelated list items --- ### Caching - Repository results can be cached in memory - The `find()` method operates on cached objects - Significantly improves performance for repeated filtering - Ideal for: - authorization checks - configuration resolution - complex user-role-setting evaluations --- ### Stored Procedures & Testing - Stored procedure execution (PDO, MSSQL) - Built-in test scripts for: - data generation - stored procedure execution - filtering validation --- ## Minimum Requirements - **PHP 7.4 or higher** - Recommended: **PHP 7.4 ? 8.0** - PHP 8.2+ is supported with minor adjustments (see `UPGRADE.md` for details) Required PHP extensions: - `mysqli` or `pdo` - `pdo_mysql` / `pdo_sqlsrv` depending on database engine --- ## Design Goals - Avoid repetitive database queries - Work with structured, typed data instead of raw arrays - Support complex domain models - Allow expressive filtering without SQL complexity - Keep business logic independent from database structure --- ## Project Status ### Implemented - Repository pattern - Attribute-based object mapping - Recursive filtering engine - DT_ITEM / DT_LIST support - Transaction handling - In-memory caching - Comparison operators - Stored procedure support ### Planned (Later Development Phase) - Database table script generation from attribute definitions - Concurrent data management - Historical data handling (`DBHistoricalRepository`) - Extended documentation - Improved function and parameter descriptions --- ## Notes This library is intentionally **not an ORM**. It focuses on predictable behavior, explicit data structures, and fine-grained control over filtering and data traversal. For PHP version upgrade notes, see `UPGRADE.md`.

Screenshots (2)  
  • example_running.jpg
  • example_running_2.jpg
  Files folder image Files (29)  
File Role Description
Files folder imagesrc (8 files, 1 directory)
Files folder imagetest (7 files, 2 directories)
Accessible without login Plain text file bootstrap.php Aux. Configuration script
Accessible without login Plain text file LICENSE Lic. licence
Accessible without login Plain text file README.md Doc. read_me
Accessible without login Plain text file UPGRADE.md Doc. upgrade

  Files folder image Files (29)  /  src  
File Role Description
Files folder imagecompat (1 file)
  Plain text file common_static_helper.php Class Class source
  Plain text file data_access_layer_helper_base.php Class Class source
  Plain text file data_access_layer_helper_mysqli.php Class Class source
  Plain text file data_access_layer_helper_pdo.php Class Class source
  Plain text file data_type_helper.php Class Class source
  Plain text file db_repository_base.php Class Class source
  Plain text file db_repository_base_mysqli.php Class Class source
  Plain text file db_repository_base_pdo.php Class Class source

  Files folder image Files (29)  /  src  /  compat  
File Role Description
  Accessible without login Plain text file poly.php Aux. Configuration script

  Files folder image Files (29)  /  test  
File Role Description
Files folder imagescript_mssql (2 files)
Files folder imagescript_mysql (5 files)
  Accessible without login Plain text file db_test.php Example Example script
  Accessible without login Plain text file login_test.php Example Class source
  Accessible without login Plain text file stored_procedure_test.php Example Example script
  Accessible without login Plain text file stored_procedure_test_simple_pdo.php Example Example script
  Plain text file userrolesetting_data_repository.php Class Class source
  Plain text file userrole_data_repository.php Class moving files
  Plain text file user_data_repository.php Class moving files

  Files folder image Files (29)  /  test  /  script_mssql  
File Role Description
  Accessible without login Plain text file getUser.storedProcedure.sql Data Auxiliary data
  Accessible without login Plain text file test.sql Data Auxiliary data

  Files folder image Files (29)  /  test  /  script_mysql  
File Role Description
  Accessible without login Plain text file test_user.sql Data Auxiliary data
  Accessible without login Plain text file test_userrole.sql Data Auxiliary data
  Accessible without login Plain text file test_userrolesetting.sql Data Auxiliary data
  Accessible without login Plain text file test_userrole_user...tingscollection.sql Data Auxiliary data
  Accessible without login Plain text file test_user_userrolescollection.sql Data Auxiliary data

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 93%
Total:59
This week:0
All time:10,526
This week:57Up
User Comments (1)
Jehhhhh
2 years ago (Róbert Tandari)
77%StarStarStarStar