E
E
ezpy2018-04-02 09:33:51
PHP
ezpy, 2018-04-02 09:33:51

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

3 answer(s)
D
Dmitry Kim, 2018-04-02
@kimono

How do you connect? Native mysql_connect? If yes, then php.net/manual/en/function.mysql-connect.php

S
SagePtr, 2018-04-02
@SagePtr

Wangyu, you are trying to connect via localhost, it resolves to [::1] and MySQL only listens on an IPv4 socket.

J
justpusher, 2018-04-02
@justpusher

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 question

Ask a Question

731 491 924 answers to any question