Yii db->beginTranscation in yii

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

                    try {


                       $model   = new UserRole();




                        Yii::log('Done', 'trace', 'stripe');


           catch (Exception $e) {



Why data’s are insert in db after that begintransaction in yii,What is $connection?i dont exactly what is meaning of $connection. In My config.php My Db connection like below.

‘db’ => require(dirname(FILE) . ‘/database.php’),

$connection = array(

‘connectionString’ => “mysql:host=localhost;dbname=xxx”,

‘username’ => “root”,

‘password’ => “”,

‘charset’ => ‘utf8’,

‘emulatePrepare’ => true,

‘tablePrefix’ => ‘tbl_’,


My databse connection in another file database.php

I got error like,

Call to a member function beginTransaction() on a non-object.

Why data’s are not insert after that beginTransaction?

Seems like problem is this line - $transaction=$connection->beginTransaction(); , cause I don’t se that U have defined $connection anywhere.

1 Like