Problem with RBAC and SQL

I try to create a simple console command to help set up the RBAC items for my application (will post it to Tips&Snippets as soon as it works ;) ). Basically i’m doing this:

<?php


    private $_db;


    private $_auth;





    public function run($args) {


        $app=Yii::app();


        if (($this->_db=$app->getDb())===null)


            die("Could not access database! Please check your db configuration.");


        $this->_db->active=true;





        $schemafile=Yii::getPathOfAlias('system.web.auth').DIRECTORY_SEPARATOR.'schema.sql';


        if (($schema=file_get_contents($schemafile))===false)


            die("Could not read schema file in $schemafile.");


        $this->_db->createCommand($schema)->execute();





        if (($this->_auth=$app->getAuthManager())===null)


            die("Could not get CAuthManager. Please check your authManager configuration.");





        foreach ($this->operations as $op)


            $this->createRBACItem($op,0);


        // [... snip...]


    }





    protected function createRBACItem($data,$type) {


            // Create Item


            if (isset($data[3]))


                $task=$this->_auth->createAuthItem($data[0],$type,$data[1],$data[3]);


            else


                $task=$this->_auth->createAuthItem($data[0],$type,$data[1]);





            // Add children


            foreach ($data[2] as $child)


                $task->addChild($child);


    }

To my surprise, the db schema is created successfully but on the first call of createAuthItem i get this error:

Quote

exception 'CDbException' with message 'CDbCommand konnte das SQL-Statement nicht ausführen: 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.' in /usr/share/php/yii-svn/db/CDbCommand.php:192

Quote

"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."

I have similar problem too. I have configured DB Logger.

log'=>array(


			'class'=>'CLogRouter',


			'routes'=>array(


				array(


					'class'=>'CDbLogRoute',


					'logTableName'=>'log',


					'connectionID'=>'db',					


				),


			),


		),

And then this error rises. without DB logger website works fine. Also i needed to create log table, because Logger couldn't handle itself… may be the problem is in my configuration?

Qiang, any idea on this?

I first thought, it's a problem to execute multiple SQL statements with one createCommand()->execute(). But all the SQL from system/web/auth/schema.sql is executed correctly. The problem comes with the next command after that.

Not sure about what's happening. Perhaps the following bug report is helpful?

http://pecl.php.net/…bug.php?id=7263

Hmm. Tried to set

$this->_db->pdoInstance->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY,true);


but no difference. Also tried this, but the pdoStatement is empty??

<?php


        if (($schema=file_get_contents($schemafile))===false)


            die("Could not read schema file in $schemafile.n");


        $command=$this->_db->createCommand($schema);


        $command->execute();


        $command->pdoStatement->closeCursor(); // Throws error 

Found a workaround:

<?php


        $this->_db->createCommand($schema)->execute();





        // Workaround for problem with unbuffered queries:


        $this->_db->active=false;


        $this->_db->active=true;


But what's the reason and will there be some good solution?

There are 2 possible solitions:

  1. upgrade to php 5.2.1 or higher where PDO::MYSQL_ATTR_USE_BUFFERED_QUERY is true by default

  2. set this option by hand

I am currently running php 5.2.9-2 and still get this error

Also get this error at bottom of page below stack trace;

What has everyone done to get this to work???

Sorry team just found answer in another topic

http://www.yiiframew…pic,2385.0.html

Quote

In your entry script, declare the following two constants to be false (before you include yii.php). Then see what happens. Most likely, you have some PHP syntax errors.