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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.