MySQL Remote Access: How to Connect MySQL Database Remotely using Codeigniter
MySQL is a popular database along with PHP applications. Sometime we need to connect MySQL Remotely. In this tutorial we will see how to connect MySQL Database Remotely.Let follow me step by step.
Remote Database Connection Setup(In Codeigniter):
To setup database connection in codeigniter application go to the file inside application/config named database.php and change database credentials as showing below.
$db['default'] = array( 'dsn' => '', 'hostname' => 'Use the Remote Server IP Address', /* For Example: 184.108.40.206 */ 'username' => 'Remote MySQL Database User Name', 'password' => 'Remote MySQL Database User Password if Applicable', 'database' => 'Remote MySQL Database Name', 'dbdriver' => 'mysqli', 'dbprefix' => '', 'pconnect' => FALSE, 'db_debug' => (ENVIRONMENT !== 'production'), 'cache_on' => FALSE, 'cachedir' => '', 'char_set' => 'utf8', 'dbcollat' => 'utf8_general_ci', 'swap_pre' => '', 'encrypt' => FALSE, 'compress' => FALSE, 'stricton' => FALSE, 'failover' => array(), 'save_queries' => TRUE );
Allowing a Remote Server to Access Your Database(MySQL Remote Access – From cPanel):
Before connecting to MySQL from another server or computer, the connecting server or computer must be enabled as an Access Host.To Enable Access Host you need to allow remote server’s IP address. To set IP address go to the cPanel and follow these steps.
- Log into cPanel and click the Remote MySQL icon, under Databases.
- Type IP address in the host box, and click the Add Host button.
- Click Add, and you should now be able to connect remotely to your database.
That’s All,thank you for reading this post. we hope you like this Post, Please feel free to comment below, your suggestion. if you face any issue with this tutorial let us know. We’d love to help!