Database Connection With Remote Ip

Hi Team am unable to connect database throuth ip host its always connecting to the localhost only

here is code:


       'connectionString' => 'mysql:host=; port=3306; unix_socket=/opt/lampp/var/mysql/mysql.sock;dbname=' . $_SESSION['dbconnect'], 

       // 'connectionString' =>   "mysql:host=localhost;dbname=mydb",

        'emulatePrepare' => true,

        'username' => 'root',

        'password' => 'root',

        // 'queryCachingDuration'  => 3000,

                'enableParamLogging'    => true,

        'charset' => 'utf8',


and am getting error like

CDbConnection failed to open the DB connection: SQLSTATE[HY000] [1130] Host ‘RAVITEJA-DESKTO’ is not allowed to connect to this MySQL server

hi raviteja, first of all you have to configure your remote database for remote access.

you can refer to my blog on this:

In may case remote database is on ‘’





//syntax of database connection


The Yii way is as follows (taken from the Guide).

Inside config/main.php set up the database connection:










            'emulatePrepare'=>true,  // needed by some MySQL installations




hi raviteja, [size="3"]the issue CDb connection failed to open the DB connection SQLSTATE[1130] not allowed to connect to this server[/size]

This error mainly happening due to bad or unsufficient privileges of phpmyadmin. So you should set correct privileges by changing privileges in localhost/phpmyadmin link.

here you could add a new user with all privileges and set that user and password in yii protected/main.php database settings


provide enough privileges to root user

Try it best of luck