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:

‘class’=>‘CDbConnection’,

       'connectionString' => 'mysql:host=10.10.11.281; 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:

satya-nitk.blogspot.in/search/label/DBMS

In may case remote database is on ‘10.100.39.172’

$hostname=‘10.100.39.172’;

$user=‘satya’;

$password=‘satya’;

$dbname=‘Amantran’;

//syntax of database connection

$con=mysqli_connect($hostname,$user,$password,$dbname)

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

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




array(

    ......

    'components'=>array(

        ......

        'db'=>array(

            'class'=>'CDbConnection',

            'connectionString'=>'mysql:host=localhost;dbname=testdb',

            'username'=>'root',

            'password'=>'password',

            '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

or

provide enough privileges to root user

Try it best of luck