Is there no mysql.default_socket in the PHP7 configuration file?

Source: Internet
Author: User
Tags phpinfo
[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;

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.