Download the PHP package ideaglory/database without Composer
On this page you can find all versions of the php package ideaglory/database. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package database
PHP Singleton Database Class
A lightweight and reusable PHP class to manage database connections using the Singleton pattern. This class ensures only one database connection instance exists during the runtime, providing an efficient and easy-to-use database interface.
Features
- Singleton pattern to prevent multiple connections.
- Parameterized query support to prevent SQL injection.
- Basic transaction management (
beginTransaction
,commit
,rollback
). - Utility methods for fetching data (
fetchAll
,fetchOne
). - Supports prepared statements with bound parameters.
- Auto-close connection and reset instance when closed.
Installation
You can install this package via Composer. Run the following command:
Usage
Basic Initialization
The Database
class uses the Singleton pattern. To initialize it:
Querying the Database
Execute a Query
To execute a query with parameters:
Fetch All Rows
Fetch a Single Row
Transactions
Begin a Transaction
Commit a Transaction
Rollback a Transaction
Close Connection
When the database connection is no longer needed:
Use Cases
- Efficient Database Management: Ensures only one instance of the database connection exists during runtime, improving resource utilization.
- Simplified Query Execution: Provides easy-to-use methods for executing queries and fetching results.
- Secure Applications: Prevents SQL injection with parameterized queries.
- Transaction Support: Handles database transactions for complex operations.
Example
Below is a complete example demonstrating various features:
Contributing
Feel free to fork this repository and submit pull requests for improvements or bug fixes.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Author
Created by IdeaGlory.