4

i have following script in php to login to mysql

  $db_host="localhost";
  $db_user="root";
  $db_pass="123";

  $dbc=mysql_connect($db_host,$db_user,$db_pass) OR DIE (mysql_error());
  $dbs=mysql_select_db($db_name) OR DIE (mysql_error());    

this script was working fine, now i reinstall the O.S now i have windows 7 and iis7 and PHP Version 5.3.2 & mysql server 5.1 but now this script is not working and taking log time to execute.

Thanks

air
  • 6,136
  • 26
  • 93
  • 125
  • It's taking a long time AND it's not working? Is your MySQLd running? Can you connect to mysql using the console or a mysql client using those credentials? – Konerak Jul 10 '10 at 09:43

3 Answers3

14

On Windows 7 localhost resolves to ::1, and MySQL doesn't support IPv6 as far as I know.

Connecting directly to 127.0.0.1 resolves this problem; but you can edit the hosts file to resolve localhost to 127.0.0.1, then localhost will work too:

  1. Open C:\Windows\System32\drivers\etc\hosts
  2. Remove the following line, if present: ::1 localhost
  3. Add the following line, if not present: 127.0.0.1 localhost
RoliSoft
  • 755
  • 1
  • 8
  • 19
4

Use:

$db_host = "127.0.0.1";

(or any other IP, such as 192.168.1.2), instead of a hostname (localhost).

Martin Tournoij
  • 26,737
  • 24
  • 105
  • 146
kanenas
  • 869
  • 1
  • 20
  • 37
0

You can also look at this link : http://dev.mysql.com/doc/refman/5.7/en/server-options.html#option_mysqld_skip-name-resolve

--skip-name-resolve option

Jerry
  • 1,141
  • 1
  • 13
  • 18