progrmanial/simplemdb

Enterprise Database Toolkit for PHP - Modern schema management, intelligent migrations, and advanced query building

v4.6.0 2025-08-02 16:23 UTC

README

🚀 Production-Ready Database Management - Build enterprise-grade applications with Laravel-like syntax, 25+ data types, intelligent migrations, and military-grade security.

Latest Version PHP Version License

⚡ 5-Minute Quick Start

Install SimpleMDB:

composer require simplemdb/simplemdb

Create your first table:

<?php
require_once 'vendor/autoload.php';

use SimpleMDB\DatabaseFactory;
use SimpleMDB\SchemaBuilder;

// Connect to database
$db = DatabaseFactory::create('pdo', 'localhost', 'root', 'password', 'myapp');

// Create modern table with enterprise features
$schema = new SchemaBuilder($db);
$schema->increments('id')                           // Auto-increment primary key
       ->string('name', 100)->comment('Full name')  // VARCHAR with comment
       ->string('email', 150)->unique()             // Unique email
       ->boolean('is_active')->default(true)        // Boolean with default
       ->json('preferences')->nullable()            // JSON data storage
       ->ipAddress('last_login_ip')->nullable()     // IPv4/IPv6 address
       ->timestamps()                               // created_at, updated_at
       ->createTable('users');

echo "✅ Modern users table created!\n";

That's it! You now have a production-ready table with modern data types and enterprise features.

👉 Try the complete quick start example →

🏆 Why Choose SimpleMDB?

Laravel-Like Developer Experience

// Familiar fluent syntax
$users = SimpleQuery::create()
    ->select(['id', 'name', 'email'])
    ->from('users')
    ->where('is_active = ?', [true])
    ->orderBy('created_at DESC')
    ->execute($db);

25+ Modern Data Types

$table->uuid('external_id')                // UUID storage
      ->ipAddress('client_ip')             // IPv4/IPv6 (45 chars)
      ->json('metadata')                   // JSON documents
      ->point('location')                  // Geographic coordinates
      ->morphs('commentable');             // Polymorphic relationships

Intelligent Migrations

// Auto-generates context-aware templates
$migrations->create('create_blog_posts_table');
// ✨ Detects "blog posts" and generates complete table structure

Enterprise Security & Performance

  • 100% SQL injection prevention with comprehensive validation
  • Memory-efficient streaming for large datasets (10-50x reduction)
  • AES-256 encryption for sensitive data
  • Connection pooling and advanced caching

Complete Database Object Management

  • Functions & Procedures with fluent parameter management
  • Views with algorithm optimization and security contexts
  • Events with flexible scheduling (one-time, recurring, intervals)
  • Triggers for data integrity and automated auditing
  • Unified Management interface for all database objects

📚 Documentation

🚀 Getting Started

🏗️ Core Features

🔄 Migration Guides

🛡️ Enterprise Features

🔄 Migration Guides

🎯 Feature Comparison

Feature SimpleMDB Laravel Schema Doctrine DBAL
Data Types ✅ 25+ types ✅ 27+ types ✅ 20+ types
Schema Validation Comprehensive ⚠️ Basic ⚠️ Basic
Migration Intelligence Smart Templates ⚠️ Static ❌ Manual
Database Objects Complete ❌ Limited ❌ Limited
Security Features Enterprise ✅ Good ✅ Good
Memory Efficiency Streaming ⚠️ Standard ⚠️ Standard
Learning Curve Gentle ⚠️ Steep ⚠️ Steep

💡 Real-World Examples

E-commerce Product Table

$schema->createTable('products', function($table) {
    $table->increments('id');
    $table->string('sku', 50)->unique();
    $table->string('name', 200);
    $table->decimal('price', 10, 2)->unsigned();
    $table->json('attributes')->nullable();             // Color, size, etc.
    $table->enum('status', ['draft', 'published'])->default('draft');
    $table->ipAddress('created_from_ip');
    $table->timestamps();
    
    $table->index(['status', 'price']);
});

User Authentication System

$schema->createTable('users', function($table) {
    $table->increments('id');
    $table->string('email')->unique();
    $table->string('password');
    $table->json('preferences')->nullable();
    $table->ipAddress('last_login_ip')->nullable();
    $table->timestamp('email_verified_at')->nullable();
    $table->rememberToken();
    $table->timestamps();
    $table->softDeletes();
});

Complete Backup Solution

use SimpleMDB\Backup\BackupManager;

$backupManager = new BackupManager($db, 'backups/');

// Memory-efficient encrypted backup
$backup = $backupManager
    ->backup('daily_backup')
    ->streaming(1000)              // Process in chunks
    ->encrypted($encryptionKey)     // AES-256 encryption
    ->compress('gzip')             // Space efficient
    ->execute();

Database Objects Management

use SimpleMDB\DatabaseObjects\DatabaseObjectManager;

$objects = new DatabaseObjectManager($db);

// Create a function
$objects->function('calculate_total')
    ->inParameter('amount', 'DECIMAL(10,2)')
    ->returns('DECIMAL(10,2)')
    ->body("RETURN amount * 1.1;")
    ->create();

// Create a view with complex logic
$objects->view('user_summary')
    ->select("
        u.id, u.name, u.email,
        COUNT(o.id) as order_count,
        SUM(o.total) as total_spent
    FROM users u
    LEFT JOIN orders o ON u.id = o.user_id
    GROUP BY u.id
    ")
    ->create();

// Create a trigger for auditing
$objects->trigger('audit_changes')
    ->after()
    ->update()
    ->on('users')
    ->body("INSERT INTO audit_log (table_name, action, record_id) VALUES ('users', 'UPDATE', NEW.id);")
    ->create();

⚙️ System Requirements

  • PHP: 8.0 or higher
  • MySQL: 5.7+ or 8.0+ (recommended)
  • MariaDB: 10.2+ (fully supported)
  • Extensions: PDO or MySQLi (at least one required)
  • Memory: 64MB minimum (128MB recommended)

🚀 Installation Options

Composer (Recommended)

composer require simplemdb/simplemdb

Manual Installation

git clone https://github.com/imrnansaadullah/SimpleMDB.git
cd SimpleMDB
composer install

Verify Installation

<?php
require_once 'vendor/autoload.php';

use SimpleMDB\DatabaseFactory;

try {
    $db = DatabaseFactory::create('pdo', 'localhost', 'root', 'password', 'test');
    echo "✅ SimpleMDB installed successfully!\n";
} catch (Exception $e) {
    echo "❌ Installation issue: " . $e->getMessage() . "\n";
}

🎓 Learning Path

Beginner (30 minutes)

  1. 5-Minute Quick Start - Basic table creation
  2. Schema Builder Basics - Understanding column types
  3. Simple Queries - SELECT, INSERT, UPDATE, DELETE

Intermediate (2 hours)

  1. Advanced Data Types - JSON, UUIDs, polymorphic types
  2. Migration System - Creating and running migrations
  3. Security Best Practices - SQL injection prevention

Advanced (1 day)

  1. Performance Optimization - Caching, connection pooling
  2. Enterprise Backup System - Complete backup solutions
  3. Production Deployment - Production best practices

🛠️ Quick API Reference

Schema Builder

// Column types
$table->string('name', 100)           // VARCHAR
$table->integer('count')              // INT
$table->boolean('active')             // TINYINT(1)
$table->json('data')                  // JSON
$table->timestamp('created_at')       // TIMESTAMP
$table->ipAddress('ip')               // VARCHAR(45)

// Modifiers
$table->nullable()                    // Allow NULL
$table->default('value')              // Default value
$table->unique()                      // Unique constraint
$table->comment('Description')        // Column comment

// Indexes
$table->index(['column'])             // Regular index
$table->unique(['email'])             // Unique index
$table->foreignKey('user_id', 'users', 'id')  // Foreign key

Query Builder

// SELECT
$users = SimpleQuery::create()
    ->select(['id', 'name', 'email'])
    ->from('users')
    ->where('active = ?', [true])
    ->execute($db);

// INSERT
$result = SimpleQuery::create()
    ->insert(['name' => 'John', 'email' => 'john@example.com'])
    ->into('users')
    ->execute($db);

// UPDATE
$result = SimpleQuery::create()
    ->update('users')
    ->set(['name' => 'Jane'])
    ->where('id = ?', [1])
    ->execute($db);

🤝 Contributing

We welcome contributions! See our Contributing Guide for details.

Quick Contribution Setup

git clone https://github.com/imrnansaadullah/SimpleMDB.git
cd SimpleMDB
composer install
php examples/quick_start_example.php  # Test your setup

📖 Resources

📜 License

MIT License - Use SimpleMDB in any project, commercial or open source.

🌟 Enterprise Ready

SimpleMDB is production-ready for enterprise applications. Join the growing community of developers who choose SimpleMDB for its combination of power, security, and developer experience.

⭐ Star us on GitHub if SimpleMDB helps you build better applications!

Need enterprise support? [Contact us](mailto:lems? @simplemdb.com) for professional services, training, and custom development.