問題描述
我正在嘗試對我的網站進行 dockerize.我已經啟動并運行了 Nginx 和 PHP,它正在工作,但我無法連接到數據庫.加載頁面時出現錯誤:
I'm trying to dockerize my website. I've got Nginx and PHP up and running and it's working find except I can't connect to a db. When the page is loaded I get the error:
Fatal error: Uncaught Error: Class 'MySQLi' not found in /private/conn.php:8 Stack trace: #0 /public_html/index.php(2): require() #1 {main} thrown in /private/conn.php on line 8
我在第 8 行的連接線是:
My connection line on line 8 is:
$db = new mysqli("$host", "$user", "$pass", "$db", "$port");
現在這曾經在我的舊設置上運行良好,但自從轉移到新設置并安裝 php7.1.5 后,我無法運行它.現在,我沒有使用過 mysqlnd,所以這可能是我的一個誤解,但 mysqlnd 包含 mysqli 驅動程序.
Now this used to work fine on my old set up but since moving to a new one and installing php7.1.5 I can't get it running. Now, I haven't used the mysqlnd so this may be a misunderstanding on my part but the mysqlnd includes the mysqli driver.
phpinfo 的輸出:
Output of phpinfo:
我怎樣才能讓它運行?還是我現在應該使用不同的驅動程序?
How can I get this running? Or should I be using a different driver now?
推薦答案
您需要在 Dockerfile 中啟用 php 擴展:
You need to enable the php extension in your Dockerfile:
FROM php:7
RUN docker-php-ext-install mysqli
無需觸摸php.ini
.
這篇關于MySQLi 未找到 dockerized php的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!