https://github.com/mpyw/laravel-pdo-emulation-control
Temporarily enable/disable PDO prepared statement emulation
https://github.com/mpyw/laravel-pdo-emulation-control
laravel pdo php
Last synced: 12 months ago
JSON representation
Temporarily enable/disable PDO prepared statement emulation
- Host: GitHub
- URL: https://github.com/mpyw/laravel-pdo-emulation-control
- Owner: mpyw
- License: mit
- Created: 2020-01-17T15:54:01.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2025-03-04T06:44:38.000Z (over 1 year ago)
- Last Synced: 2025-06-20T21:12:53.574Z (12 months ago)
- Topics: laravel, pdo, php
- Language: PHP
- Homepage:
- Size: 42 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Laravel PDO Emulation Control
[](https://github.com/mpyw/laravel-pdo-emulation-control/actions) [](https://coveralls.io/github/mpyw/laravel-pdo-emulation-control?branch=master)
Temporarily enable/disable PDO prepared statement emulation.
## Requirements
| Package | Version | Mandatory |
|:--------|:--------------------------------------|:---------:|
| PHP | ^8.2 | ✅ |
| Laravel | ^11.0 || ^12.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
[
/* ... */
Mpyw\LaravelPdoEmulationControl\ConnectionServiceProvider::class,
/* ... */
],
];
```
```php
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