laikait/laika-model

A PDO Database Model

Installs: 656

Dependents: 1

Suggesters: 0

Security: 0

Stars: 1

Watchers: 0

Forks: 0

Open Issues: 0

Type:project

pkg:composer/laikait/laika-model

v2.0.5 2026-01-27 19:40 UTC

This package is auto-updated.

Last update: 2026-01-27 19:47:16 UTC


README

Laika Model 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

Install with composer:

composer require laikait/laika-model

Connection Manager

Configure your database settings in your PHP application page top section. To config use ConnectionManager::add(array $config, string $name = 'default'). Array $config: * 'driver' => [Required]: Accepted mysql/pgsql/sqlite. Example: mysql * 'host' => [Optional]: localhost/127.0.0.1 || [Required]: If Foreign. Example: otherhost * 'port' => [Optional]: 3306 || [Required]: If Port is Not 3306 * 'database'=> [Required]: Your Database Name. Example: 'dbname' * 'username'=> [Required]: Your Database Username. Example: 'db_username' * 'password'=> [Required]: Your Database Password. Example: 'db_password'

String $name: Default is 'default'. Has Read & Write Access

use Laika\Model\Connection;

// Require Autoload File
require_once("./vendor/autoload.php");
// Add Default Connection Manager
Connection::add(array $config); // DB Default Connection Details for Read & Write both

/**
 * Add Multiple Connection Manager. Default is for read, write or foreign
 */
Connection::add(array $config, 'other'); // DB Another Connection for Read & Write. Local or Foreign
Connection::add(array $ReadDbConfig, 'read'); // DB Connection Details for Read
Connection::add(array $WriteDbConfig, 'write'); // DB Connection Details for Write

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 PDO Connection

// Get Default PDO Connection
$pdo = Connection::get();

// Get Read PDO Connection if Configured
$pdo = Connection::get('read');
// Get Write PDO Connection if Configured
$pdo = Connection::get('write');
// Get Other PDO Connection if Configured
$pdo = Connection::get('other');

Now you can execute any query by using any PDO methods.

Get Laika Model Pre-build Methods

To use Laika Pre-build methods instead of PDO Methods you can use DB Class from Laika model.

use Laika\Model\Model;

// Get Default DB Model
$model = new Model();

// Get Read DB Model if Configured
$model = new Model('read');
// Get Write DB Model if Configured
$model = new Model('write');
// Get Other DB Model if Configured
$model = new Model('other');

// Get All Columns Data from Table
$data = $model->table('table')->get();

// Get Selected Columns Data from Table
$data = $model->table('table')->select('column1,column2,column3')->get();

// Get Data from Table By Using Strings in Where Clause
$data = $model->table('table')->where(['column' => 'valjue'])->get();
// OR
// Get Data from Table By Using Array in Where Clause
$data = $model->table('table')->where(['id' => 1,'country'=>'usa'], '=', 'AND')->get();