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
"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.
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?
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.
<?php
$this->_db->createCommand($schema)->execute();
// Workaround for problem with unbuffered queries:
$this->_db->active=false;
$this->_db->active=true;
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.