Search code examples
phpmysqlmysql-connect

mysql_connect taking long time to execute


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


Solution

  • 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