/** * Executes the given sql statement(s). * * @param mixed sql statement(s) * @return mixed sql statement(s) (imploded) or false */ private function executeSql($sql) { try { $sql = (array) $sql; foreach ($sql as $sql1) { $cmd = new CDbCommand(self::$db, $sql1); $cmd->prepare(); $cmd->execute(); $this->afterSave(); $this->refresh(); } return implode("\n", $sql); } catch (CDbException $ex) { $this->afterSave(); if ($this->throwExceptions) { throw new DbException($cmd); } else { $errorInfo = $cmd->getPdoStatement()->errorInfo(); $this->addError(null, Yii::t('core', 'sqlErrorOccured', array('{errno}' => $errorInfo[1], '{errmsg}' => $errorInfo[2]))); return false; } } }
/** * Constructor. * @param CDbCommand $command the command generating the query result */ public function __construct(CDbCommand $command) { $this->_statement = $command->getPdoStatement(); $this->_statement->setFetchMode(PDO::FETCH_ASSOC); }