0

Is it possible to connect a hosted PHP server on the internet to a database on my home LAN?

What should I do? Here's my Example Connection Database:

$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'www.mydomainname.com';
$db['default']['username'] = 'myusername';
$db['default']['password'] = 'mypassword';
$db['default']['database'] = 'mydabatasenameoncloud';
$db['default']['dbdriver'] = 'mysqli';  
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = FALSE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

//-- Poll.php (My LAN Connection.)

$config['hostname'] = 'localhost';
$config['username'] = 'root';
$config['password'] = ''; 
$config['database'] = 'mydatabasenameonlan';
$config['dbdriver'] = 'mysqli';
$config['dbprefix'] = '';
$config['pconnect'] = FALSE;
$config['db_debug'] = FALSE;
$config['cache_on'] = FALSE;
$config['cachedir'] = '';
$config['char_set'] = 'utf8';
$config['dbcollat'] = 'utf8_general_ci';
$config['swap_pre'] = '';
$config['autoinit'] = TRUE;
$config['stricton'] = FALSE;

$DB2 = $this->load->database($config, TRUE);
$DB3 = $this->load->database('default', TRUE);

$check_if_connected = $DB2->initialize();

So, this is my Reversed database connection. Cloud to Lan database connection. But I'm getting an error. Can I Remote MySQL on XAMPP?

Donald Duck
  • 8,409
  • 22
  • 75
  • 99
Mia Torres
  • 21
  • 8
  • whats the reason behind of that, because i cant imagine one single case where you need to connect to your localhost DB from a Remote machine - and didn't you asking this already here (http://stackoverflow.com/questions/23168441/connecting-to-remote-server-database-using-php-codeigniter/42199411#42199411) ? – Atural Feb 15 '17 at 08:52
  • Removed redundant code, formatting, and thank you message. Clarified question. – symcbean Feb 15 '17 at 12:09
  • hey Sintakonte: I'm already done connecting to localhost --- > localhost and lan --> cloud.. my main problem now is how to connect my database connection using my Hosted site to LAN(XAMPP). – Mia Torres Feb 16 '17 at 05:21

1 Answers1

0

You're making default connection correctly as below -

$db['default']['hostname'] = "localhost";
$db['default']['username'] = "root";
$db['default']['password'] = "";
$db['default']['database'] = "mydabatasenameonlan";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = FALSE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";
$db['default']['swap_pre'] = "";
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

But in your second database connection define cofigurations as below -

$db['otherdb']['hostname'] = "www.mydomainname.com";
$db['otherdb']['username'] = "myusername";
$db['otherdb']['password'] = "mypassword";
$db['otherdb']['database'] = "mydatabasenameoncloud";
$db['otherdb']['dbdriver'] = "mysql";
$db['otherdb']['dbprefix'] = "";
$db['otherdb']['pconnect'] = TRUE;
$db['otherdb']['db_debug'] = FALSE;
$db['otherdb']['cache_on'] = FALSE;
$db['otherdb']['cachedir'] = "";
$db['otherdb']['char_set'] = "utf8";
$db['otherdb']['dbcollat'] = "utf8_general_ci";
$db['otherdb']['swap_pre'] = "";
$db['otherdb']['autoinit'] = TRUE;
$db['otherdb']['stricton'] = FALSE;

Then you can connect to cloud database as below -

$otherdb = $this->load->database('otherdb', TRUE);

You can also see this answer - Codeigniter - multiple database connections

Community
  • 1
  • 1