Download the PHP package oshco/db-exceptions-logger without Composer
On this page you can find all versions of the php package oshco/db-exceptions-logger. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package db-exceptions-logger
Database Exceptions Logger
A WebFiori framework extension that logs exceptions to a database with optional per-portal tracking. Currently supports SQL Server only.
Requirements
- PHP 8.1 or later
- WebFiori Framework v3.0+
- SQL Server with ODBC Driver 18
Installation
Setup
1. Create the database table
Run the migration to create the system_exceptions table:
2. Register the error handler
3. (Optional) Configure portal tracking
To associate exceptions with a specific portal, set a resolver callable:
The resolver is called when an exception occurs. It should return an int (portal ID) or null.
Usage
Querying logged exceptions
Entity properties
Each SystemException entity exposes:
| Method | Description |
|---|---|
getId() |
Auto-increment ID |
getHash() |
SHA-256 hash for deduplication |
getDate() |
Timestamp when the exception was logged |
getCode() |
Exception code |
getClass() |
Class where the exception was thrown |
getExceptionClass() |
The exception's fully-qualified class name |
getMessage() |
Exception message |
getLine() |
Line number |
getUrl() |
Request URL |
getParameters() |
Request parameters |
getTrace() |
Stack trace |
getPortalId() |
Portal ID (null if not set) |
How It Works
When an exception occurs, DatabaseErrHandler:
- Captures exception details (code, class, message, file, line, stack trace)
- Captures request context (URL, parameters)
- Resolves the portal ID via the configured resolver (if set)
- Computes a SHA-256 hash for deduplication
- Stores everything in the
system_exceptionstable viaExceptionsRepository
Database Schema
| Column | Type | Nullable | Description |
|---|---|---|---|
id |
INT (PK, identity) | No | Auto-increment ID |
hash |
NVARCHAR(128) | No | SHA-256 hash for deduplication |
date |
DATETIME2 | No | Timestamp (defaults to now) |
code |
INT | No | Exception code |
class |
VARCHAR(128) | No | Class where exception was thrown |
exception_class |
VARCHAR(128) | No | Exception class name |
message |
NVARCHAR(2048) | No | Exception message |
line |
INT | No | Line number |
url |
NVARCHAR(2048) | Yes | Request URL |
parameters |
NVARCHAR(2048) | Yes | Request parameters |
trace |
NVARCHAR(2048) | No | Stack trace |
portal_id |
INT | Yes | Portal where exception occurred |
Classes
| Class | Description |
|---|---|
DatabaseErrHandler |
Error handler that captures exceptions and delegates storage to the repository. Supports a configurable portal ID resolver. |
ExceptionsRepository |
Repository providing CRUD and filtering operations on the system_exceptions table. |
SystemExceptionsTable |
Attribute-based MSSQL table schema definition. |
SystemException |
Entity representing a logged exception record. |
CreateSystemExceptionsTable |
Migration that creates the base table. |
AlterSystemExceptionsAddPortalId |
Migration that adds the portal_id column (safe for existing tables). |
Running Tests
Requires a running SQL Server instance:
License
MIT
Statistics Methods
All statistics methods accept optional $from and $to date parameters (ISO format) for filtering by date range.