mysqli not found in (php-fpm) docker container

99封情书 提交于 2021-02-07 14:27:10

问题


I'm running php:7-fpm in a docker container that is used by my nginx web server. Everything is working nicely except for when I'm trying to instantiate a mysqli connection in my PHP code. I receive the following error:

"NOTICE: PHP message: PHP Fatal error:  Uncaught Error: Class 'Listener\mysqli' not found in index.php:104

Here's my Dockerfile for building the image, where I explicitly install the mysqli extension:

FROM php:7-fpm

RUN docker-php-ext-install mysqli

It appears to be installed given the phpinfo() output below. Do I need to configure or enable it somehow?


回答1:


Your problem isn't that you're missing the mysqli extension.

If you're doing something like this:

namespace Listener;

class Foo
{
    public function bar() {
        $conn = new mysqli(...);
    }
}

Then PHP will interpret new mysqli() as new \Listener\mysqli() because you're currently in the \Listener namespace. To fix this, you can just explicitly anchor mysqli() to the root namespace:

$conn = new \mysqli(...);


来源:https://stackoverflow.com/questions/43809491/mysqli-not-found-in-php-fpm-docker-container

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!