在(php-fpm)docker容器中找不到mysqli [英] mysqli not found in (php-fpm) docker container
问题描述
我正在运行
您的问题不是您缺少mysqli扩展名.
如果您正在执行以下操作:
命名空间侦听器;Foo类{公共功能bar(){$ conn =新的mysqli(...);}}
然后,PHP将把 new mysqli()
解释为 new \ Listener \ mysqli()
,因为您当前位于 \ Listener
命名空间中.要解决此问题,您可以将 mysqli()
明确锚定到根名称空间:
$ conn = new \ mysqli(...);
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?
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(...);
这篇关于在(php-fpm)docker容器中找不到mysqli的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!