Answer the question
In order to leave comments, you need to log in
Why is it not connecting to the database?
Hello.
I am using php 7.1. I'm trying to connect to the database through localhost, but the connection does not occur.
Through 127.0.0.1 everything is connected perfectly.
What this problem can be connected with, with php versions below 7.0 everything works fine.
Answer the question
In order to leave comments, you need to log in
How do you connect? Native mysql_connect? If yes, then php.net/manual/en/function.mysql-connect.php
Wangyu, you are trying to connect via localhost, it resolves to [::1] and MySQL only listens on an IPv4 socket.
If you are not on Windows, when you connect to mysql on 127.0.0.1, the connection goes over the network, and when on localhost - through unix-socket. php looks for the required socket in the php.ini settings, and mysql looks for it in my.cnf. You probably have different socket settings in your configs.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question