MonkeyslegionDB is a database connection manager designed specifically for the Monkeyslegion PHP framework. It provides a robust set of features for handling database connections, query building, transactions, and logging.
- Connection Pooling: Efficiently manage and reuse database connections.
- Query Builder: Construct SQL queries programmatically.
- Transactions: Execute a group of operations atomically.
- Logging: Log SQL queries and debug issues.
- PHP 8.2 or higher
- Composer for dependency management
To install MonkeyslegionDB, run the following Composer command:
composer require monkeyslegion/monkeyslegiondb
use Monkeyslegion\\MonkeyslegionDB\\ConnectionPool;
$connection = ConnectionPool::getConnection();
setConfig(array $config): void
: Sets the database configuration.getConnection(): PDO
: Retrieves a PDO connection from the pool.releaseConnection(PDO $connection): void
: Releases a PDO connection back to the pool.
use Monkeyslegion\\MonkeyslegionDB\\QueryBuilder;
$query = (new QueryBuilder())
.select('*')
.from('users')
.where('id', '=', 1)
.build();
select(string $columns): self
: Sets the columns to select.from(string $table): self
: Sets the table to query from.where(string $column, string $operator, mixed $value): self
: Adds a WHERE condition.build(): string
: Builds and returns the SQL query.
use Monkeyslegion\\MonkeyslegionDB\\Transaction;
$transaction = new Transaction($connection);
$transaction->begin();
// ... perform operations
$transaction->commit();
begin(): bool
: Begins a new transaction.commit(): bool
: Commits the current transaction.rollback(): bool
: Rolls back the current transaction.
use Monkeyslegion\\MonkeyslegionDB\\Logger;
$dbLogger = new Logger($yourPsr3Logger);
$dbLogger->logQuery('SELECT * FROM users WHERE id = ?', [1]);
logQuery(string $query, array $params = []): void
: Logs an executed SQL query.logError(string $message): void
: Logs an error message.
For detailed documentation, please visit our documentation site.
We welcome contributions! Please see our contributing guidelines for more details.
MonkeyslegionDB is open-source software licensed under the MIT license.