PHP code example of mpyw / laravel-pdo-emulation-control

1. Go to this page and download the library: Download mpyw/laravel-pdo-emulation-control 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/ */

    

mpyw / laravel-pdo-emulation-control example snippets




return [

    /* ... */

    'providers' => [
        /* ... */

        Mpyw\LaravelPdoEmulationControl\ConnectionServiceProvider::class,

        /* ... */
    ],

];



use Illuminate\Support\Facades\DB;

// Temporarily enable PDO prepared statement emulation.
DB::emulated(function () {
    // Your code goes here
});

// Temporarily disable PDO prepared statement emulation.
// (Only if you've already configured your connection by options [PDO::ATTR_EMULATE_PREPARES => true])
DB::native(function () {
    // Your code goes here    
});



namespace App\Providers;

use App\Database\MySqlConnection;
use Illuminate\Database\Connection;
use Illuminate\Support\ServiceProvider;

class DatabaseServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        Connection::resolverFor('mysql', function (...$parameters) {
            return new MySqlConnection(...$parameters);
        });
    }
}



namespace App\Database;

use Illuminate\Database\Connection as BaseMySqlConnection;
use Mpyw\LaravelPdoEmulationControl\ControlsEmulation;

class MySqlConnection extends BaseMySqlConnection
{
    use ControlsEmulation;
}