PHP code example of furkifor / sql_dumper

1. Go to this page and download the library: Download furkifor/sql_dumper library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

furkifor / sql_dumper example snippets


$sql_dumper = new Furkifor\SqlDumper("users");

// Simple query
echo $sql_dumper->select('*')->get();
// SELECT * FROM users

// Query with conditions
echo $sql_dumper->select('name, email')
    ->where('age > ?', [18])
    ->orderBy('name', 'DESC')
    ->limit(10)
    ->get();
// SELECT name, email FROM users WHERE age > ? ORDER BY name DESC LIMIT 10

// JOIN operations
echo $sql_dumper->select('users.*, roles.name as role_name')
    ->join('INNER', 'roles', 'users.role_id = roles.id')
    ->where('users.active = ?', [1])
    ->get();
// SELECT users.*, roles.name as role_name FROM users 
// INNER JOIN roles ON users.role_id = roles.id WHERE users.active = ?

// Grouping and HAVING
echo $sql_dumper->select('country, COUNT(*) as user_count')
    ->groupBy('country')
    ->having('user_count > 100')
    ->get();
// SELECT country, COUNT(*) as user_count FROM users 
// GROUP BY country HAVING user_count > 100

$table = new MigrateClass("mysql");

// Simple table creation
$table->name("users")
    ->string('username', 255)->unique()->notnull()
    ->string('email', 255)->unique()->notnull()
    ->string('password', 255)->notnull()
    ->datetime('created_at')->default("CURRENT_TIMESTAMP")
    ->createTable();

// Table with relationships
$table->name("posts")
    ->string('title', 255)->notnull()
    ->text('content')
    ->int('user_id')->notnull()
    ->foreignKey('user_id', 'users', 'id')
    ->datetime('published_at')->nullable()
    ->boolean('is_published')->default(0)
    ->createTable();

// Table with custom constraints
$table->name("products")
    ->string('name', 100)->notnull()
    ->decimal('price', 10, 2)->notnull()
    ->int('stock')->notnull()->default(0)
    ->check('price > 0')
    ->check('stock >= 0')
    ->createTable();