doctrine / orm

Doctrine Object Relational Mapper (ORM)
https://www.doctrine-project.org/projects/orm.html
MIT License
9.92k stars 2.51k forks source link

doctrine orm 控制台执行 sql 命令,显示异常,永远显示:`0 rows affected`。而不会显示对应的记录 #11411

Closed vkviyu closed 5 months ago

vkviyu commented 5 months ago

Bug Report

Q A
BC Break No
Version doctrine/orm 3.1.0 php8.1.27

Summary

在使用Doctrine的dbal:run-sql命令执行SQL查询时,没有正确地输出查询结果,而是显示"0 rows affected"。

Current behavior

当我运行php doctrine.php dbal:run-sql "show databases"命令时,我期望看到我所有的数据库列表。但是,实际上我看到的输出是"0 rows affected",并没有显示任何数据库。

How to reproduce

  1. 在doctrine.php文件中,设置数据库连接参数。如下图: image

  2. 在终端中,运行php doctrine.php dbal:run-sql "show databases"命令。如下图: image

Expected behavior

我期望dbal:run-sql命令能正确地输出SQL查询的结果。在这个例子中,我期望看到我所有的数据库列表。我不确定这个 bug 在新版本的 doctrine/orm 中是否得到了解决,但因为一些原因我无法去升级我的 php 版本。

derrabus commented 5 months ago

Please write issues in English, please.

ywisax commented 4 months ago

It is because "dbal:run-sql" recognize your sql as a statement, not a query. You can use "force-fetch" option to force run query.

Check \Doctrine\DBAL\Tools\Console\Command\RunSqlCommand::doExecute