[UPDATE] Just check the documentation, PHP7 has not supported the MySQL extension, but how should I solve the problem can only use the 127.0.0.1 link, cannot use the localhost link?
......................................................................................................
Why do you have this problem?
I wrote a PHP script link database, the code is as follows, when if MySQL address is 127.0.0.1, then can be able to link, if the address changed to localhost, then prompt ' PHP warning:mysqli::mysqli (): (hy000/ 2002): No such file or directory in/home/wwwroot/default/cenyu/goitems/goitems/connect_mysql.php on line 9
`
$mysqli = new mysqli("127.0.0.1", "root", "root", "wordpress");if (mysqli_connect_errno()) { echo 'Error: Could not connect to database. Please try again later.'; echo "\n"; exit;}else{ echo "Connect! \n";}$sql = "SELECT * FROM wp_amz_key;";$result = $mysqli->query($sql);/* close connection */$mysqli->close();
Then I searched for some workarounds, mainly to modify the values of these three options in the php.ini configuration file.
pdo_mysql.default_socket=/tmp/mysql.sockmysql.default_socket=/tmp/mysql.sockmysqli.default_socket = /tmp/mysql.sock
And then my question came up:
My Ubuntu use is PHP7, through phpinfo find php.ini files, opened, nomysql.default_socket
Parameters, only the other two, and then I look at the version of the php.ini discovery is there mysql.default_socket
, so ask PHP7 configuration file There is no mysql.default_socket?
So, my question is:
1. There is a problem with the linked database in the script, can it be solved by this method?
Is the php.ini configuration file in 2.php7 not mysql.default_socket, or am I installing a problem?
Thank you, big God.
Reply content:
[UPDATE] Just check the documentation, PHP7 has not supported the MySQL extension, but how should I solve the problem can only use the 127.0.0.1 link, cannot use the localhost link?
......................................................................................................
Why do you have this problem?
I wrote a PHP script link database, the code is as follows, when if MySQL address is 127.0.0.1, then can be able to link, if the address changed to localhost, then prompt ' PHP warning:mysqli::mysqli (): (hy000/ 2002): No such file or directory in/home/wwwroot/default/cenyu/goitems/goitems/connect_mysql.php on line 9
`
$mysqli = new mysqli("127.0.0.1", "root", "root", "wordpress");if (mysqli_connect_errno()) { echo 'Error: Could not connect to database. Please try again later.'; echo "\n"; exit;}else{ echo "Connect! \n";}$sql = "SELECT * FROM wp_amz_key;";$result = $mysqli->query($sql);/* close connection */$mysqli->close();
Then I searched for some workarounds, mainly to modify the values of these three options in the php.ini configuration file.
pdo_mysql.default_socket=/tmp/mysql.sockmysql.default_socket=/tmp/mysql.sockmysqli.default_socket = /tmp/mysql.sock
And then my question came up:
My Ubuntu use is PHP7, through phpinfo find php.ini files, opened, nomysql.default_socket
Parameters, only the other two, and then I look at the version of the php.ini discovery is there mysql.default_socket
, so ask PHP7 configuration file There is no mysql.default_socket?
So, my question is:
1. There is a problem with the linked database in the script, can it be solved by this method?
Is the php.ini configuration file in 2.php7 not mysql.default_socket, or am I installing a problem?
Thank you, big God.
Nomysql.default_socket
But there are mysqli.default_socket
andpdo_mysql.default_socket
Because of the mysqli, PHP7 no longer supports old MySQL extensions.
However, we usually connect MySQL via IP and port, in which case we do not need to specify what default_socket.
$db = new mysqli('127.0.0.1','root','pass','mysql',3306);
No, it's just a straight line.
Even if you want to connect to MySQL via the socket, you can also specify it at the time of connection:
$db = new mysqli(null,'root','pass','mysql',null,'/path/to/mysqld.sock');
So there is no need to tangle with anything.
There is no difference between using the socket and using the IP address.
1, check the MySQL configuration file my.conf If there is a line bind-address = 127.0.0.1
, if any, add the # comment or delete the restart MySQL
2. Check whether the MySQL account allows the linked host to be limited to 127.0.0.1
SELECT User, Host FROM mysql.user;