mpyw/laravel-pdo-emulation-control 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mpyw/laravel-pdo-emulation-control

Composer 安装命令:

composer require mpyw/laravel-pdo-emulation-control

包简介

Temporarily enable/disable PDO prepared statement emulation

README 文档

README

Temporarily enable/disable PDO prepared statement emulation.

Requirements

Package Version Mandatory
PHP ^8.2
Laravel ^11.0 || ^12.0 || ^13.0 || ^14.0
PHPStan >=2.0

Note

Older versions have outdated dependency requirements. If you cannot prepare the latest environment, please refer to past releases.

Installing

composer require mpyw/laravel-pdo-emulation-control

Basic Usage

Important

The default implementation is provided by ConnectionServiceProvider, however, package discovery is not available. Be careful that you MUST register it in config/app.php by yourself.

<?php

return [

    /* ... */

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

        Mpyw\LaravelPdoEmulationControl\ConnectionServiceProvider::class,

        /* ... */
    ],

];
<?php

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    
});

Important

Note that DB::getPdo() DB::getReadPdo() are not always called even though these methods directly touch the PDO instances. Connections are lazily resolved as possible as they can. PDO::setAttribute() is called only after the PDO instance has been created and the socket connection to the database has been really established.

Advanced Usage

Tip

You can extend Connection classes with ControlsEmulation trait by yourself.

<?php

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);
        });
    }
}
<?php

namespace App\Database;

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

class MySqlConnection extends BaseMySqlConnection
{
    use ControlsEmulation;
}

统计信息

  • 总下载量: 80.8k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 2
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-01-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固