Is there no mysql.default_socket in the configuration file of php7?

WBOY
Release: 2023-03-03 10:26:02
Original
2200 people have browsed it

[Update] I just checked the documentation and noticed that PHP7 no longer supports mysql extension, but how should I solve the problem that I can only use 127.0.0.1 link and cannot use localhost link?

…………………………………………………………………………………………………………

Why is there this problem?
I wrote a PHP script to connect to the database. The code is as follows. If the address of mysql is 127.0.0.1, it can be connected. If the address is changed to localhost, it will 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
`

<code>$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();
</code>
Copy after login
Copy after login

Then I searched for some solutions, mainly modifying the values ​​of these three options in the php.ini configuration file

<code>pdo_mysql.default_socket=/tmp/mysql.sock
mysql.default_socket=/tmp/mysql.sock
mysqli.default_socket = /tmp/mysql.sock</code>
Copy after login
Copy after login

Then my problem arises:
I use php7 on ubuntu. I checked the php.ini file through phpinfo. After opening it, there is no mysql.default_socket
parameter, only the other two, and then I I checked the version of php.ini and found that there is mysql.default_socket, so is there no mysql.default_socket in the configuration file of PHP7?
So, my questions are:
1. There is a problem with the database link in the script. Can this be solved by this method?
2. Is there no mysql.default_socket in the php.ini configuration file in PHP7, or is there something wrong with my installation?
Thank you in advance

Reply content:

[Update] I just checked the documentation and noticed that PHP7 no longer supports mysql extension, but how should I solve the problem that I can only use 127.0.0.1 link and cannot use localhost link?

…………………………………………………………………………………………………………

Why is there this problem?
I wrote a PHP script to connect to the database. The code is as follows. If the address of mysql is 127.0.0.1, it can be connected. If the address is changed to localhost, it will 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
`

<code>$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();
</code>
Copy after login
Copy after login

Then I searched for some solutions, mainly modifying the values ​​of these three options in the php.ini configuration file

<code>pdo_mysql.default_socket=/tmp/mysql.sock
mysql.default_socket=/tmp/mysql.sock
mysqli.default_socket = /tmp/mysql.sock</code>
Copy after login
Copy after login

Then my problem arises:
I use php7 on ubuntu. I checked the php.ini file through phpinfo. After opening it, there is no mysql.default_socket
parameter, only the other two, and then I I also checked the version of php.ini and found that there is mysql.default_socket, so is there no mysql.default_socket in the configuration file of PHP7?
So, my questions are:
1. There is a problem with the database link in the script. Can this be solved by this method?
2. Is there no mysql.default_socket in the php.ini configuration file in PHP7, or is there something wrong with my installation?
Thank you in advance

There is no mysql.default_socket
but there are mysqli.default_socket and pdo_mysql.default_socket
Because of mysqli, PHP7 no longer supports the old mysql extension.

However, we usually connect to MySQL through IP and port. In this case, there is no need to specify a default_socket.
Directly $db = new mysqli('127.0.0.1','root','pass','mysql', 3306);That’s it.
Even if you want to connect to MySQL through socket, you can also specify it when connecting:
$db = new mysqli(null,'root','pass','mysql',null,' /path/to/mysqld.sock');
So there is no need to worry about anything.

If they are all local, there is no difference between using socket and IP address.

1. Check if there is a line bind-address = 127.0.0.1 in the mysql configuration file my.conf. If there is, add a # comment or delete it and restart mysql

2. Check whether the host allowed by the mysql account is limited to 127.0.0.1
SELECT User, Host FROM mysql.user;

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template