An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# Laravel PDO Emulation Control
[![Build Status](https://github.com/mpyw/laravel-pdo-emulation-control/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/mpyw/laravel-pdo-emulation-control/actions) [![Coverage Status](https://coveralls.io/repos/github/mpyw/laravel-pdo-emulation-control/badge.svg?branch=master)](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