phingofficial/phing

PHP 8 "There is no active transaction" with a pdosqlexec with transaction

Closed this issue · 2 comments

Describe the bug
Since the PHP 8 update having an xml block for pdosqlexec with a transaction will trigger the following error message upon building

BUILD FAILED
/build.xml:361:138: /build.xml:361:138: There is no active transaction

Steps To Reproduce

Having a block like the following will trigger it

<pdosqlexec url="xxxx:host=xxxx" encoding="xxxx" userid="xxxxx" password="xxxx" onerror="abort">
            <transaction>DROP DATABASE IF EXISTS `xxxxx`;</transaction>
            <transaction>CREATE DATABASE `xxxxx`;</transaction>
</pdosqlexec>

Expected behavior
It should run the query without any warnings as pre-PHP8.

Additional context
This seems to be a known issue with other packages that run migrations or provide DB abstraction layers.
doctrine/migrations#1104
yiisoft/yii2#18406

@victorjkhalaf thanks for the bug report - it was fixed in the attached PR

I am using dev-main, but this fix still doesn't work, except if I add autocommit="true to pdosqlexec.

so this is NOT working:

        <pdosqlexec url="${db.pdo.driver}:host=${db.host}"
            userId="${db.user}" password="${db.password}"
            onerror="abort">
                DROP DATABASE IF EXISTS `${call.db.name}`;
                CREATE DATABASE `${call.db.name}`;
        </pdosqlexec>

this is working (enabling autocommit):

        <pdosqlexec url="${db.pdo.driver}:host=${db.host}"
            userId="${db.user}" password="${db.password}"
            autocommit="true" onerror="abort">
                DROP DATABASE IF EXISTS `${call.db.name}`;
                CREATE DATABASE `${call.db.name}`;
        </pdosqlexec>

But I would assume, that this is still not as expected. The drop and create should work no matter if autocommit is on or off.