witham Posted March 17, 2008 Share Posted March 17, 2008 I hope someone can help I have set up xampp from apache friends on a laptop and written a php & mysql database which works fine. I loaded the same software, databases and php scripts onto another computer giving it the ip 192.168.0.5 but it will not connect: These are the variables I am using to try and connect: $dbuser = ''; // your database server user name $dbhost = '192.168.0.5'; // name of the sql server $dbpass = 'root'; // your database server password $dbname = 'weld'; // the name of the database to connect to and this is the mysql_connect and mysql_select_db // mysql_connect connects to the database server and returns a link to the the resource $dblink = @mysql_connect("$dbhost","$dbpass") or die("<p><b>Could not connect to database server: ($dbhost)</b></p>\n"); // mysql_select_db selects a database to use on the database server pointers to by $dblink // the @ sign before the command supresses any error messages @mysql_select_db ($dbname , $dblink) or die ("<p><b>Could not connect to database ($dbname)</b></p>\n"); Quote Link to comment https://forums.phpfreaks.com/topic/96518-cannot-connect-to-server/ Share on other sites More sharing options...
wildteen88 Posted March 17, 2008 Share Posted March 17, 2008 You can substitute the computers IP address with localhost instead if mysql is install locally. You only need to specifiy the ip address if MySQL is install remotely on another computer/server. Also always use mysql_error() function to retrieve errors from mysql. // mysql_connect connects to the database server and returns a link to the the resource $dblink = @mysql_connect("$dbhost","$dbpass") or die("<p><b>Could not connect to database server: ($dbhost)</b><br />" . mysql_error() . "</p>\n"); // mysql_select_db selects a database to use on the database server pointers to by $dblink // the @ sign before the command supresses any error messages @mysql_select_db ($dbname , $dblink) or die ("<p><b>Could not connect to database ($dbname)</b><br />" . mysql_error() . "</p>\n"); Quote Link to comment https://forums.phpfreaks.com/topic/96518-cannot-connect-to-server/#findComment-494205 Share on other sites More sharing options...
witham Posted March 18, 2008 Author Share Posted March 18, 2008 Thanks very much for the assistance I have managed to connect. Quote Link to comment https://forums.phpfreaks.com/topic/96518-cannot-connect-to-server/#findComment-495317 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.