Yii2 with PDO::ATTR_EMULATE_PREPARES = 0

Why Yii2 does not work with PDO::ATTR_EMULATE_PREPARES = 0?

I met 2 problems:

  1. Does not works migrations. Did not sow error messages.

  2. Does not works inner transactions. On calling beginTransaction() secondly Yii2 throw exception.

Is Yii teem plan to fix it?

  1. What happens exactly? Anything in logs or on screen at all?

  2. Which exception? Do you have a stacktrace? Code to reproduce it?

Updated: Sorry I mean. PDO::ATTR_EMULATE_PREPARES = 0

Db: 10.2.6-MariaDB

PHP: 7.1.8 NTS

Db config:


return [

    'class' => 'yii\db\Connection',

    'dsn' => 'mysql:host=127.0.0.1;dbname=db',

    'username' => 'username',

    'password' => 'pass',

    'charset' => 'utf8',

    'tablePrefix' => '',

    'attributes' => [

        \PDO::ATTR_EMULATE_PREPARES => false,

        \PDO::ATTR_STRINGIFY_FETCHES => false,

    ],

];


class m141022_115823_test extends Migration

{

    public function safeUp()

    {

        $this->execute("SET foreign_key_checks = 0;");

        $sql = <<< SQL

            CREATE TABLE IF NOT EXISTS `test` (

              `id` int(11) NOT NULL AUTO_INCREMENT,

              `date` int(11) NOT NULL,

              PRIMARY KEY (`id`)

            ) ENGINE=InnoDB AUTO_INCREMENT=497 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;


          


SQL;

        $this->execute($sql);


        $this->execute("SET foreign_key_checks = 1;");

    }


    public function safeDown()

    {

    }



With one CREATE no problem. When add another CREATE table it fails on vendor/yiisoft/yii2/db/Command.php:837.


$this->prepare(false);

2:

Code for reproduce in controller:


  

        $boilerTest1 = new Boiler();

        $boilerTest2 = new Boiler();

        $boilerTest3 = new Boiler();

        $boilerTest4 = new Boiler();

        $boilerTest1->title = 'test1';

        $boilerTest2->title = 'test2';

        $boilerTest3->title = 'test3';

        $boilerTest4->title = 'test4';


        $outerTransaction = \Yii::$app->db->beginTransaction();

        $boilerTest1->save();


        $innerTransaction = \Yii::$app->db->beginTransaction();

        $boilerTest2->save();

        $innerTransaction->rollBack();


        $innerTransaction2 = \Yii::$app->db->beginTransaction();

        $boilerTest3->save();

        $innerTransaction2->rollBack();


        $boilerTest4->save();

        $outerTransaction->commit();



Exception rised on this line:


$innerTransaction = \Yii::$app->db->beginTransaction();

Exception message:




"SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active.  Consider using PDOStatement::fetchAll().  Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.\nThe SQL being executed was: SAVEPOINT LEVEL1"



Sounds like a bug. Please report to https://github.com/yiisoft/yii2/issues. Thanks.