PHP code example of memran / marwa-db

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

    

memran / marwa-db example snippets



return [
    'default' => [
        'driver'      => 'mysql',
        'host'        => '127.0.0.1',
        'port'        => 3306,
        'database'    => 'app',
        'username'    => 'root',
        'password'    => '',
        'charset'     => 'utf8mb4',
        'retry'       => 3,
        'retry_delay' => 300,
        'debug'       => true,
    ],
];

use Marwa\DB\Facades\DB;

$users = DB::table('users')
    ->where('status', 'active')
    ->orderBy('created_at', 'desc')
    ->limit(5)
    ->get();

DB::table('users')->insert([
    'name' => 'Jane Doe',
    'email' => '[email protected]',
]);

use App\Models\User;

// Create record
$user = User::create([
    'name' => 'John Doe',
    'email' => '[email protected]'
]);

// Find & update
$user = User::find(1);
$user->email = '[email protected]';
$user->save();

// Soft delete
$user->delete();

class User extends Model {
    public function posts() {
        return $this->hasMany(Post::class);
    }
}

class Post extends Model {
    public function author() {
        return $this->belongsTo(User::class, 'user_id');
    }
}

use Marwa\DB\Schema\Schema;

Schema::create('users', function($table) {
    $table->increments('id');
    $table->string('name')->nullable();
    $table->string('email')->unique();
    $table->timestamps();
});

'debug' => true

use Marwa\DB\Support\DebugPanel;
DebugPanel::render();
bash
php bin/marwa-db list
bash
php bin/marwa-db make:migration create_users_table
bash
php bin/marwa-db migrate
bash
php bin/marwa-db migrate:rollback