MySQLi 未找到 dockerized php

2021-12-25 00:00:00 docker php mysqli mysqlnd

我正在尝试对我的网站进行 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.

相关文章