How to Connect Server Database from Localhost

It is very easy to connect server database from localhost. In this tutorial, we will see how to connect server databases from local server.

 To connect to server db mean to use remote MySQL connection, First of all we have to activate remote MySQL from cPanel.

How to Connect Server Database from Localhost

Login to cpanel.

Go to remote MySQL option.

Add wildcard(%) and save.

Now simply we need to change connection parameters in localhost connection file.Then we have to include connection file in all other pages where need MySQL connection.


$db['host'] = 'server IP address here';
$db['user'] = 'server db username';
$db['pass']   = 'server db password';
$db['name'] = 'server dbname';
$db['port'] = '3306';

$conn = mysqli_connect($db['host'],$db['user'],$db['pass'],$db['name'], $db['port']);
if (mysqli_connect_errno($conn)) {
  trigger_error('Database connection failed: '  . mysqli_connect_error());

Leave a Reply

Your email address will not be published. Required fields are marked *