Jump to content

Cannot connect to server


witham

Recommended Posts

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");

 

Link to comment
https://forums.phpfreaks.com/topic/96518-cannot-connect-to-server/
Share on other sites

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");

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.