PHP code example of mgx / slimdb

1. Go to this page and download the library: Download mgx/slimdb 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/ */

    

mgx / slimdb example snippets


use Mgx\Slimdb\Connect;

$config = [
    'host'     => 'localhost',
    'dbname'   => 'test_db',
    'username' => 'root',
    'password' => '',
];

$db = Connect::getInstance($config);

use Mgx\Slimdb\Migration\Migration;
use Mgx\Slimdb\TableBlueprint;

class CreateUsersTable extends Migration
{
    public function up()
    {
        $this->create('users', function (TableBlueprint $table) {
            $table->id();
            $table->string('name', 100);
            $table->string('email')->unique();
            $table->string('password', 60);
            $table->timestamps();
        });
    }

    public function down()
    {
        $this->drop('users');
    }
}

use Mgx\Slimdb\Seeder;

class UsersSeeder extends Seeder
{
    public function run(): void
    {
        $this->seedTable('users', [
            [
                'name' => 'Admin',
                'email' => '[email protected]',
                'password' => password_hash('123456', PASSWORD_DEFAULT)
            ]
        ]);
    }
}

use Mgx\Slimdb\QueryBuilder;

$qb = new QueryBuilder($db);

// Tüm kullanıcıları çek
$users = $qb->table('users')->select()->get();

// Filtreli sorgu
$admins = $qb->table('users')->where('email', 'LIKE', '%admin%')->get();
bash
php ornekler/Migration_Runner_ornek.php
bash
php ornekler/DatabaseSeeder.php
bash
php ornekler/ornekcli.php migrate      # Tüm migration'ları çalıştırır
php ornekler/ornekcli.php rollback     # Son migration'ı geri alır
php ornekler/ornekcli.php status       # Migration durumunu gösterir
php ornekler/ornekcli.php new <name>   # Yeni migration dosyası oluşturur