Aureole Posted March 26, 2008 Share Posted March 26, 2008 I have 2 servers, I'd like to use one for the database, images and css and another for all of the php. How do I go about accessing another server's database? Quote Link to comment https://forums.phpfreaks.com/topic/97995-2-servers-one-for-database/ Share on other sites More sharing options...
wildteen88 Posted March 26, 2008 Share Posted March 26, 2008 By specifying the ipaddress/hostname for the SQL database: $remote_sql_conn = mysql_connect('serverhostname/ipaddress', 'user', 'pass'); mysql_select_db('remote_db', $remote_sql_conn);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/97995-2-servers-one-for-database/#findComment-501387 Share on other sites More sharing options...
Aureole Posted March 26, 2008 Author Share Posted March 26, 2008 Thanks a lot, I shall give it a try now. Quote Link to comment https://forums.phpfreaks.com/topic/97995-2-servers-one-for-database/#findComment-501388 Share on other sites More sharing options...
trq Posted March 26, 2008 Share Posted March 26, 2008 Of course you will also need to make sure that your database user has permssion to connect from one host to another. Quote Link to comment https://forums.phpfreaks.com/topic/97995-2-servers-one-for-database/#findComment-501389 Share on other sites More sharing options...
Aureole Posted March 26, 2008 Author Share Posted March 26, 2008 I am getting the following error: Warning: mysql_connect() [function.mysql-connect]: Lost connection to MySQL server at 'reading initial communication packet', system error: 110 in /home/gamingre/public_html/alpha/sources/classes/class_database.php on line 26 Quote Link to comment https://forums.phpfreaks.com/topic/97995-2-servers-one-for-database/#findComment-501542 Share on other sites More sharing options...
wildteen88 Posted March 26, 2008 Share Posted March 26, 2008 Add or die(mysql_error()); at the end of the mysq_connect() function call, eg: $remote_sql_conn = mysql_connect('serverhostname/ipaddress', 'user', 'pass') or die('Connection error: ' . mysql_error()); it is better to retrieve the error from MySQL than PHP. Quote Link to comment https://forums.phpfreaks.com/topic/97995-2-servers-one-for-database/#findComment-501573 Share on other sites More sharing options...
Aureole Posted March 26, 2008 Author Share Posted March 26, 2008 The error is basically the same: Connection error: Lost connection to MySQL server at 'reading initial communication packet', system error: 110 Quote Link to comment https://forums.phpfreaks.com/topic/97995-2-servers-one-for-database/#findComment-501584 Share on other sites More sharing options...
wildteen88 Posted March 26, 2008 Share Posted March 26, 2008 Searching google this appears to be a hostname or ipaddress issue. What are you using to connect to the remote mysql server? Quote Link to comment https://forums.phpfreaks.com/topic/97995-2-servers-one-for-database/#findComment-501588 Share on other sites More sharing options...
Aureole Posted March 26, 2008 Author Share Posted March 26, 2008 Sorry, I checked google and I didn't find any results that helped. I tried both a domain and an IP Address. This is basically all you need, right? <?php $this->vars['db_host'] = 'veraci7y.net'; $this->vars['db_user'] = '...'; $this->vars['db_pass'] = '...'; $this->connection = mysql_connect( $this->vars['db_host'], $this->vars['db_user'], $this->vars['db_pass'] ) or die( 'Connection error: ' . mysql_error() ); ?> Quote Link to comment https://forums.phpfreaks.com/topic/97995-2-servers-one-for-database/#findComment-501615 Share on other sites More sharing options...
wildteen88 Posted March 26, 2008 Share Posted March 26, 2008 Try providing the port number for the database aswell $this->vars['db_host'] = 'veraci7y.net:3306'; Also verify that the MySQL server at veraci7y.net is allowing for remote connections, which thorpe suggested earlier. Quote Link to comment https://forums.phpfreaks.com/topic/97995-2-servers-one-for-database/#findComment-501625 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.