Skip to content

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.

License

Notifications You must be signed in to change notification settings

MonkeysLegion/monkeyslegiondb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MonkeyslegionDB

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.

Features

  • 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.

Requirements

  • PHP 8.2 or higher
  • Composer for dependency management

Installation

To install MonkeyslegionDB, run the following Composer command:

composer require monkeyslegion/monkeyslegiondb

Usage

Connection Pooling

use Monkeyslegion\\MonkeyslegionDB\\ConnectionPool;

$connection = ConnectionPool::getConnection();

Functions

  • 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.

Query Building

use Monkeyslegion\\MonkeyslegionDB\\QueryBuilder;

$query = (new QueryBuilder())
.select('*')
.from('users')
.where('id', '=', 1)
.build();

Functions

  • 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.

Transactions

use Monkeyslegion\\MonkeyslegionDB\\Transaction;

$transaction = new Transaction($connection);
$transaction->begin();
// ... perform operations
$transaction->commit();

Functions

  • begin(): bool: Begins a new transaction.
  • commit(): bool: Commits the current transaction.
  • rollback(): bool: Rolls back the current transaction.

Logging

use Monkeyslegion\\MonkeyslegionDB\\Logger;

$dbLogger = new Logger($yourPsr3Logger);
$dbLogger->logQuery('SELECT * FROM users WHERE id = ?', [1]);

Functions

  • logQuery(string $query, array $params = []): void: Logs an executed SQL query.
  • logError(string $message): void: Logs an error message.

Documentation

For detailed documentation, please visit our documentation site.

Contributing

We welcome contributions! Please see our contributing guidelines for more details.

License

MonkeyslegionDB is open-source software licensed under the MIT license.

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages