Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

localhost vs computer name


Guest

Recommended Posts

Hi,

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:

<?php 

//$link = mysql_connect('192.168.1.101', 'test', 'test'); // Will work
//$link = mysql_connect('MyHomePC', 'test', 'test');	 // Will work
//$link = mysql_connect('127.0.0.1', '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';
mysql_close($link);

?>

 

Can anybody explain me what's up here?

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

 

Thanks.

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.

 

Vger

Link to comment
Share on other sites

The host file located here:

C:\WINDOWS\system32\drivers\etc

It's called:

hosts

 

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:

#

# 102.54.94.97 rhino.acme.com # source server

# 38.25.63.10 x.acme.com # x client host

 

127.0.0.1 localhost

 

That's all there is.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...