Download the PHP package a-le/microdbal without Composer
On this page you can find all versions of the php package a-le/microdbal. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package microdbal
microDbal
microDbal is a minimal PHP database abstraction layer.
It wraps PDO to give you clean, safe, and simple database access.
🚀 Why microDbal?
- ✅ Micro by design – no ORM, no query builder, no dependencies, no annotations
- ✅ Just SQL in, data out – fetch results as arrays or objects
- ✅ Great for prototyping or learning SQL from a PHP-first perspective
- ✅ Write raw SQL your way – use named (:name) or positional (?) placeholders
- ✅ Run prepared statements and fetch results in a single step
- ✅ Inspired by the PDO article series from PHP Delusions
💬 If you like microDbal, leave a ⭐ on GitHub — it really helps!
Tested with those Databases
Firebird, MySQL / MariaDB, MS SQL Server, PostgreSQL, SQLite.
Should support any database that is compatible with PHP's PDO.
Installation
Install via Composer:
Or alternatively:
Simply drop MicroDbal.php into your project folder and include it manually.
Usage
Note: SQL must be adapted to your targeted database. The following examples use SQL syntax for SQLite.
1. Autoload with composer
Or alternatively:
2. Connect to the Database
3. Run Queries
4. Get All Rows
Output:
5. Get a Single Row
Output:
6. Get a Single Column
Output:
7. Get a Single Value
Output:
8. Get Affected Rows
Output:
9. Get Last Inserted ID
Output:
10. Get Column Metadata
Output:
11. Transactions
12. Fetch Objects
13. SQL IN Helper
14. SQL LIKE Helper
15. Access the PDO Instance
The underlying PDO instance is exposed as a public property: $db->pdo.
You can use it directly for uncovered operations or to integrate with other libraries that expect a PDO object.
For example, using delight-im/PHP-Auth, which requires a PDO connection:
16. Access the PDO Statement Object
The run method returns a standard PDOStatement object, which you can use as needed — for example, to manually fetch rows one by one:
This gives you full control over result fetching, especially useful for large datasets or custom processing.
FAQ
What happens if there is an error?
- This library enforces
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, which ensures that PDO will throw an exception (PDOException) whenever an error occurs. - These exceptions can be handled like any other PHP error using
try...catchblocks.
Common setups for dealing with PHP errors:
-
Development Environment:
- Display errors for debugging purposes.
- Example configuration in
php.ini:
- Production Environment:
- Log errors instead of displaying them to the user.
- Example configuration in
php.ini:
With these configurations:
- In development, errors will be displayed to help with debugging.
- In production, errors will be logged to a file to avoid exposing sensitive information to users.
If you need to recover from an error, you can use a try...catch block to handle the exception and continue the script's execution.
For more information about the rationale behind this approach, see: PHP Delusions - Try Catch
Running Tests
To run tests using PHPUnit:
-
Clone the repository with composer :
-
Run tests on SQLite (default to memory DB if no DSN provided) :
-
Run tests on any database connection :
Example
Status
First stable version just released (april, 2025).
🤝 Contributing
Contributions are very welcome!
Feel free to open an issue for bug reports, feature requests, or questions.
🛠️ This library aims to remain micro.
If you'd like to submit a pull request, please open an issue or discussion first to make sure it aligns with the project's goals.
License
This project is licensed under the MIT License. See the LICENSE file for details.