-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ensureForwardCompatibilityStatement expects ResultStatement, given PDOStatement #4603
Comments
I have a similar error when using debugbar:
Integrated in two places: |
I have the same error when i run php artisan migrate:generate error info: Argument 1 passed to Doctrine\DBAL\Connection::ensureForwardCompatibilityStatement() must be an instance of Doctrin |
@gezilixu: 2.13.x is broken in certain setups (to be identified yet which), until then a workaround is to downgrade:
|
@mwoods-familiaris If I'm right, you are talking of this issue : #4564. If I'm wrong, can you provide a code sample to reproduce please. |
Yeah, and fix seems to be in #4590 |
Agreed - not sure how I didn't spot that when I searched, but does appear to be the same bug. |
@glensc I'm affraid that the fix here will not fully answer your expectations. If the user has already wrapped the \PDOStatement, it will be overidden in the DriverManager. <?php
require_once('vendor/autoload.php');
class MyPDOStatement extends \PDOStatement
{
public function execute($input_parameters = null)
{
var_dump('Hello there');
return parent::execute($input_parameters);
}
}
$pdo = new PDO('sqlite::memory:');
$pdo->setAttribute(\PDO::ATTR_STATEMENT_CLASS, [MyPDOStatement::class, []]);
$conn = Doctrine\DBAL\DriverManager::getConnection(['pdo' => $pdo, 'driver' => 'pdo_sqlite']);
$result = $conn->executeQuery('SELECT 1;');
var_dump($result->fetchFirstColumn()); |
@mdumoulin outside of this edge case with a custom statement class, the original issue reported here was fixed by your PR #4591 or not? |
@mdumoulin I'm still a bit confused on all of this. 2.13 has broken our implementation and is a bit of a circular dependency for us as well. I'm getting the following error:
Does $pdoConnection = PDOConnection::getInstance(); // Instance of \PDO
$dbalParams = [
'pdo' => $pdoConnection,
];
$dbalConfig = new Configuration();
// We don't want to add any overhead on production and won't be doing any query debugging
if (!$env->isProduction()) {
$dbalConfig->setSQLLogger(new DebugStack());
}
$connection = new DoctrineConnection($dbalParams, new MySQLDriver(), $dbalConfig); // Extended instance of Doctrine\DBAL\Connection |
@oojacoboo You can use a PDOConnection, but the result of query execution must return a DBAL\Driver\Statement object instead of a \PDOStatement object to be compatible with DBAL. This comment give a way of doing it : #4619 (comment) |
@mdumoulin I'm not using |
@oojacoboo Yes, I think, I understood. You have to make your PDO connection return a Dbal statement instead of PDOStatement when executing a query. I haven't the full context here, but this may work for you : <?php
use \Doctrine\DBAL\Driver\PDO\Statement as PDODriverStatement;
$pdoConnection = PDOConnection::getInstance(); // Instance of \PDO
$pdoConnection->setAttribute(PDO::ATTR_STATEMENT_CLASS, [PDODriverStatement::class, []]);
$dbalParams = [
'pdo' => $pdoConnection,
];
$dbalConfig = new Configuration();
// We don't want to add any overhead on production and won't be doing any query debugging
if (!$env->isProduction()) {
$dbalConfig->setSQLLogger(new DebugStack());
}
$connection = new DoctrineConnection($dbalParams, new MySQLDriver(), $dbalConfig); // Extended instance of Doctrine\DBAL\Connection |
@mdumoulin this results in the following error:
It might be helpful to have some boilerplate code or docs on how to use a |
The PDODriverStatement in my example is derived of \PDOStatement : https://github.com/doctrine/dbal/blob/2.13.x/lib/Doctrine/DBAL/Driver/PDO/Statement.php#L7
I can't find it either, but this feature has been removed from version 3.0. You may find some useful informations here : #3545 |
I am using doctrine/dbal:2.10.2 but having the same issue when trying to run migration. How can I fix this please? |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Bug Report
TypeError: Argument 1 passed to Doctrine\DBAL\Connection::ensureForwardCompatibilityStatement() must be an instance of Doctrine\DBAL\Driver\ResultStatement, instance of PDOStatement given, called in ./vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php on line 1313
Summary
executeQuery in Connection.php obtains the statement via:
link
which is used in a forward compatibility check, added in this release:
link
However, ensureForwardCompatibilityStatement expects $stmt to be an instance of ResultStatement, however in the case of a PDO connection, a PDOStatement is returned instead, hence the type error.
link
How to reproduce
Execute a parameterized query using a PDO connection.
Expected behaviour
ensureForwardCompatibilityStatement parameter type should cater to all possible statement types.
The text was updated successfully, but these errors were encountered: