PHP code example of pader / amphp-eloquent-mysql

1. Go to this page and download the library: Download pader/amphp-eloquent-mysql 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/ */

    

pader / amphp-eloquent-mysql example snippets


use AmphpEloquentMysql\Connection;
use Illuminate\Database\Capsule\Manager;
use Illuminate\Support\Facades\DB;

$capsule = new Manager();

$capsule->getDatabaseManager()->extend('ampmysql', function($config, $name) {
	$config['name'] = $name;
	return new Connection($config);
});

// Create connection
$capsule->addConnection([
	'driver' => 'ampmysql',
	'host' => '127.0.0.1',
	'database' => 'test',
	'username' => 'root',
	'password' => '',
	'charset' => 'utf8mb4',
	'port' => 3306,
	'collation' => 'utf8mb4_general_ci',
	'prefix' => '',
]);

// Set can be visit as global static
$capsule->setAsGlobal();

// Boot Eloquent (can ignore this if you use QueryBuilder only)
$capsule->bootEloquent();

DB::swap($capsule->getDatabaseManager());

// Initialized finished, you can use it now

$item = DB::table('users')->first();