-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugfix: deallocate mysqli prepared statement
Long running processes might hit the `max_prepared_stmt_count` due not deallocating the statement correctly.
- Loading branch information
Showing
3 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\DBAL\Tests\Functional\Driver\Mysqli; | ||
|
||
use Doctrine\DBAL\Driver\Mysqli\Statement; | ||
use Doctrine\DBAL\Exception\DriverException; | ||
use Doctrine\DBAL\Statement as WrapperStatement; | ||
use Doctrine\DBAL\Tests\FunctionalTestCase; | ||
use Doctrine\DBAL\Tests\TestUtil; | ||
use Error; | ||
use mysqli_sql_exception; | ||
use PHPUnit\Framework\Attributes\RequiresPhpExtension; | ||
use ReflectionProperty; | ||
|
||
#[RequiresPhpExtension('mysqli')] | ||
class StatementTest extends FunctionalTestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
if (TestUtil::isDriverOneOf('mysqli')) { | ||
return; | ||
} | ||
|
||
self::markTestSkipped('This test requires the mysqli driver.'); | ||
} | ||
|
||
public function testStatementsAreDeallocatedProperly(): void | ||
{ | ||
$statement = $this->connection->prepare('SELECT 1'); | ||
|
||
$property = new ReflectionProperty(WrapperStatement::class, 'stmt'); | ||
$property->setAccessible(true); | ||
|
||
$driverStatement = $property->getValue($statement); | ||
|
||
$mysqliSProperty = new ReflectionProperty(Statement::class, 'stmt'); | ||
$mysqliSProperty->setAccessible(true); | ||
|
||
$mysqliStatement = $mysqliSProperty->getValue($driverStatement); | ||
|
||
unset($statement, $driverStatement); | ||
|
||
$this->expectException(Error::class); | ||
$this->expectExceptionMessage('mysqli_stmt object is already closed'); | ||
|
||
$mysqliStatement->execute(); | ||
} | ||
} |