Jump to content
  • Checkout
  • Login
  • Get in touch


The e-commerce.

localhost vs computer name


Recommended Posts


I installed Apache, PHP, MySQL on my WinXPpro system and then spent almost a week :angry: trying to connect to MySQL from Php. Finaly (accidentally) found out that if I use my Computer Name instead of localhost it WORKS ! :D

In other words:


//$link = mysql_connect('', 'test', 'test'); // Will work
//$link = mysql_connect('MyHomePC', 'test', 'test');	 // Will work
//$link = mysql_connect('', 'test', 'test');		// Won't work
//$link = mysql_connect('localhost', 'test', 'test');		 // Won't work

if (!$link) {
  die('Could not connect: ' . mysql_error());
echo 'Connected successfully';



Can anybody explain me what's up here?

What network or other settings will make localhost work for me?



Link to comment
Share on other sites

It's a lot easier setting up a Linux server on Win XP Home, because it does not come bundled with Windows IIS server.


Your computer probably alreayd had a 'Hosts' file which defined 'localhost' as your computer name. I'm not sure where this 'Hosts' file is located, or what the file extension is, but I do know that it's a hidden file - so you have to unhide or include Hidden Files in a search.



Link to comment
Share on other sites

The host file located here:


It's called:



Here is the file's content:

# Copyright © 1993-1999 Microsoft Corp.


# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.


# This file contains the mappings of IP addresses to host names. Each

# entry should be kept on an individual line. The IP address should

# be placed in the first column followed by the corresponding host name.

# The IP address and the host name should be separated by at least one

# space.


# Additionally, comments (such as these) may be inserted on individual

# lines or following the machine name denoted by a '#' symbol.


# For example:


# rhino.acme.com # source server

# x.acme.com # x client host localhost


That's all there is.

Link to comment
Share on other sites


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

  • Create New...