hi,你好!欢迎访问本站!登录
本站由简数采集腾讯云宝塔系统阿里云强势驱动
当前位置:首页 - PHP问题 - 正文 请牢记本站网址www.sosophp.cn

php没法衔接数据库【php题目】

2019-11-26PHP问题搜搜PHP网53°c
A+ A-

PHP没法衔接数据库的解决办法总结:

1、猎取当前 mysql.default_socket、mysqli.default_socket、pdo_mysql.default_socket 设置信息

竖立一个 PHP 文件,显现 phpinfo(),用浏览器翻开如图:

在此页面,找到mysql.default_socket、mysqli.default_socket、pdo_mysql.default_socket信息

2、猎取 MySQL socket 途径

经由过程控制台进入 MySQL, 输入敕令: STATUS, 查找 UNIX socket 值

#mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.11 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

mysql> STATUS
--------------
mysql  Ver 14.14 Distrib 5.7.11, for osx10.9 (x86_64) using  EditLine wrapper

Connection id:        8
Current database:    
Current user:        root@localhost
SSL:            Not in use
Current pager:        less
Using outfile:        ‘‘
Using delimiter:    ;
Server version:        5.7.11 MySQL Community Server (GPL)
Protocol version:    10
Connection:        Localhost via UNIX socket
Server characterset:    utf8
Db     characterset:    utf8
Client characterset:    utf8
Conn.  characterset:    utf8
UNIX socket:        /tmp/mysql.sock
Uptime:            8 days 15 hours 1 min 17 sec

Threads: 2  Questions: 21  Slow queries: 0  Opens: 114  Flush tables: 1  Open tables: 0  Queries per second avg: 0.000
--------------

3、这时候, 你对照 mysql.default_socket、mysqli.default_socket、pdo_mysql.default_socket 和 经由过程 MySQL UNIX socket 发明不一样, 这就是 mysql_connect(); 正告的缘由: PHP 设置 mysql 有题目。

4、重新设置 PHP, 翻开php.ini修正mysql.default_socket、mysqli.default_socket、pdo_mysql.default_socket 的值为: /tmp/mysql.sock

pdo_mysql.default_socket=/tmp/mysql.sock  
mysql.default_socket=/tmp/mysql.sock  
mysqli.default_socket=/tmp/mysql.sock

或许修正my.cnf的socket:

[client]  
socket=/tmp/mysql.sock  
  
[mysqld]  
socket=/tmp/mysql.sock

5、重启nginx或许apache

引荐教程:PHP视频教程

以上就是php没法衔接数据库的细致内容,更多请关注ki4网别的相干文章!

  选择打赏方式
微信赞助

打赏

QQ钱包

打赏

支付宝赞助

打赏

  选择分享方式
  移步手机端
php没法衔接数据库【php题目】

1、打开你手机的二维码扫描APP
2、扫描左则的二维码
3、点击扫描获得的网址
4、可以在手机端阅读此文章