首頁 >後端開發 >PHP問題 >php不連接資料庫

php不連接資料庫

藏色散人
藏色散人原創
2019-10-18 10:02:252987瀏覽

php不連接資料庫

php不連接資料庫?

PHP連線不上MySQL解決方案總結

1. 取得目前mysql.default_socket、mysqli.default_socket、pdo_mysql.default_socket 設定資訊

#建立一個PHP 檔案, 顯示phpinfo():

用瀏覽器開啟:

php不連接資料庫

#在此頁面,找到mysql.default_socket、mysqli.default_socket 、pdo_mysql.default_socket資訊:

php不連接資料庫

 

 #SQL

## 

 #SQL

#2. 取得MySQL socket 路徑

 

 #SQL

#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 和透過MyIX sockSQL 發現不一樣,這就是mysql_connect(); 警告的原因: PHP 配置mysql 有問題.

 4. 重新配置PHP, 打開php.ini修改mysql.default_socket、mysqli.default_socket、pdo_my修改.default_socketsql.default_socketsql.default_socketsql.default_socketsql.default_socketsql.default_socketsql.default_socketsql.default_socketsql.的值為: /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 ###### ######5.重啟nginx或apache ######更多PHP相關知識,請造訪###PHP中文網###! ###

以上是php不連接資料庫的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
上一篇:php不能輸出?下一篇:php不能輸出?