cb-master / cbm-model
A database model for cloud bill master application use.
Installs: 54
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:package
This package is auto-updated.
Last update: 2025-05-03 19:31:18 UTC
README
Cloud Bill Master Singleton Database Model is a PHP-based project that implements a robust, object-oriented database management system for handling complex transactions and data manipulation tasks. Built on top of MySQL, this singleton model aims to provide a high-performance, flexible, and secure way to interact with databases in PHP applications, specifically designed to streamline billing and cloud data management systems.
Key Features
- Object-Oriented Structure: Built with PHP OOP principles, ensuring code reusability, scalability, and maintainability.
- Custom Database and Model Classes: Uses a custom Database class for managing database connections, queries, and transactions, and a Model class to represent data entities in the application.
- Secure Transactions: Implements ACID-compliant transactions for consistent and reliable data handling.
- Dynamic Query Builder: Supports dynamic query generation with a range of options for filters, sorting, and pagination, making it easy to create complex queries without directly writing SQL.
- Error Handling: Comprehensive error handling and logging for tracking and debugging issues efficiently.
- Scalable Architecture: Designed with scalability in mind, suitable for all type of PHP applications.
- Easy Integration: Integrates seamlessly with other PHP-based applications and frameworks, allowing flexible deployment in diverse environments.
Technologies Used
- PHP (Object-Oriented): Core programming language, providing OOP features for structure and maintainability.
- MySQL: Relational database management system used for data storage, with optimized queries for faster performance.
- PDO (PHP Data Objects): Utilized for secure database access with prepared statements to prevent SQL injection.
Installation
Use Without Composer: Download the source code and copy it in your application directory. For manual installation, please remove the require vendor autoload file and use the 'model.php' file from the repository.
require_once('path/cbm-model/model.php');
Install with composer:
composer require cb-master/cb-model
Configure your database settings in your PHP application page top section.
use CBM\Model\Model; // Require Autoload File require_once("./vendor/autoload.php"); // Config DB Model Model::config([ 'driver' => 'mysql', 'host' => 'localhost', 'name' => 'database_name', 'user' => 'database_user_here', 'password' => 'database_password_here' ]); // Add 'port' Key if you are not using the default port. /** * Model::config([ * 'driver' => 'mysql', * 'host' => 'localhost', * 'port' => 12345, * 'name' => 'database_name', * 'user' => 'database_user_here', * 'password' => 'database_password_here', * ]) * */
By default fetching data as object. But you can fetch data as array.
// Config DB Model Model::config([ 'driver' => 'mysql', 'host' => 'localhost', 'name' => 'database_name', 'user' => 'database_user_here', 'password' => 'database_password_here',, 'object' => false ]);
You can ignore the driver key if you are using the mysql driver. Mysql is the default driver in this system.
// Config DB Model Model::config([ 'host' => 'localhost', 'name' => 'database_name', 'user' => 'database_user_here', 'password' => 'database_password_here', ]);
Usage
This project provides a base for any PHP application needing a reliable and efficient database model, especially useful for billing and cloud services. For detailed usage examples, please see the given method implementation below.
Get Data From Table
// Get All Data With Select * Model::table('table_name')->get(); // Get All Data With Selected Columns Model::table('table_name')->get('column_1, column_2, column_3, .....'); // Get Single Data Model::table('table_name')->single();
Get Data From Table
Use Where Clause. Where clause need 3 arguments {where(array $where, string $operator = '=', string $compare = 'AND')} where 1st one is required.
// Get All Data Model::table('table_name')->where(['status'=>'active'])->get(); // Get All Data With Multiple Array Keys Model::table('table_name')->where(['status'=>'active', 'email'=>'verified'])->get(); // Get Data With Multiple where() method. Model::table('table_name')->where(['status'=>'active'])->where(['id'=>10], '>')->get();
Use between() method. Its like where. You also can use it with where() method. Between method needs 3 arguments {between(string $column, int|string $min, int|string $max, string $compare = 'AND')}
// Get All Data Between min and max Model::table('table_name')->between('id', 1, 10)->get(); // Get All Data Between min and max with multiple condition Model::table('table_name')->between('id', 1, 10)->between('id', 50, 60)->get();
Get Limited Data From Table (Default is 20)
Additional method to use is limit()
// Get Data for Default Limit 20 Model::table('table_name')->limit()->get(); // Get Data for Default Limit 20 With Offset Model::table('table_name')->limit()->offset(0)->get(); // Custom Limit Set Model::table('table_name')->limit(40)->get();