MySQL 由于缺少 PHP 扩展,CakePHP 3 无法连接到数据库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29403450/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 13:25:39  来源:igfitidea点击:

CakePHP 3 is NOT able to connect to the database due to a missing PHP extension

mysqlcakephp

提问by Le Duy Khanh

I am trying to install cakePHP 3.0.0 with WT-NMP, but i got this message:

我正在尝试使用 WT-NMP 安装 cakePHP 3.0.0,但我收到以下消息:

CakePHP is NOT able to connect to the database.

Database driver Cake\Database\Driver\Mysql cannot be used due to a missing PHP extension or unmet dependency

CakePHP 无法连接到数据库。

数据库驱动 Cake\Database\Driver\Mysql 由于缺少 PHP 扩展或未满足的依赖项而无法使用

my php.ini has this:

我的 php.ini 有这个:

extension = php_bz2.dll
extension = php_curl.dll
extension = php_gd2.dll
extension = php_imap.dll
extension = php_mbstring.dll
extension = php_exif.dll
extension = php_mysql.dll
extension = php_mysqli.dll
extension = php_pdo_mysql.dll
extension = php_pdo.dll
extension = php_soap.dll
extension = php_sockets.dll
extension = php_sqlite3.dll
extension = php_openssl.dll
extension = php_fileinfo.dll
extension = php_intl.dll

the app.php has this

app.php 有这个

    'default' => [
        'className' => 'Cake\Database\Connection',
        'driver' => 'Cake\Database\Driver\Mysql',
        'persistent' => false,
        'host' => 'localhost',
        /**
         * CakePHP will use the default DB port based on the driver selected
         * MySQL on MAMP uses port 8889, MAMP users will want to uncomment
         * the following line and set the port accordingly
         */
        'port' => '3306',
        'username' => 'root',
        'password' => '',
        'database' => 'test',
        'encoding' => 'utf8',
        'timezone' => 'UTC',
        'cacheMetadata' => true,

What am I missing? or this is cakePHP 3.0 bug? OR anything to do with WT-NMP. I have been stuck for whole day.

我错过了什么?或者这是 cakePHP 3.0 的错误?或任何与 WT-NMP 相关的事情。我被困了一整天。

回答by Le Duy Khanh

Solved this by luck!:

幸运地解决了这个问题!:

extension = php_intl.dll
extension = php_pdo_mysql.dll
intl.default_locale = en_utf8
intl.error_level = E_WARNING

回答by Ash

Installing the modules for MySQL database connectionssolved it for me:

为 MySQL 数据库连接安装模块为我解决了这个问题:

#Install the package
sudo apt-get install php5-mysql
#Restart Apache
sudo service apache2 restart

Source: http://guru4cakephp.blogspot.nl/2015/04/install-cakephp-3-on-ubuntu.html

来源:http: //guru4cakephp.blogspot.nl/2015/04/install-cakephp-3-on-ubuntu.html

Package details: https://packages.debian.org/sid/php5-mysql

包详情:https: //packages.debian.org/sid/php5-mysql

回答by Amit Dangwal

Try this:

尝试这个:

For PHP 7.0

对于 PHP 7.0

sudo apt-get install php7.0-mysql

For PHP 5:

对于 PHP 5:

sudo apt-get install php5-mysql

回答by icc97

The error message is because of extension = php_pdo_mysql.dllnot being installed and enabled in php.ini. If you don't have php_intl.dllenabled you will get an error before checking the database connection.

错误消息是因为extension = php_pdo_mysql.dll未在php.ini. 如果您没有php_intl.dll启用,您将在检查数据库连接之前收到错误消息。

Your php.iniindicates that you have got php_pdo_mysql.dllenabled, however it may have been that you needed to restart the CakePHP serverbin/cake server.

php.ini表示您已php_pdo_mysql.dll启用,但是您可能需要重新启动CakePHP 服务器bin/cake server

回答by Johna

Don't just depend on the php.ini reading. Just check if you have installed php[v]-mysql extension. You can check if php_mysql.dll exist in the php extension directory(most probably <path to your php installation>/ext) in your windows based server. In linux you can use the following command check if it is installed.

不要仅仅依赖于 php.ini 的阅读。只需检查您是否安装了 php[v]-mysql 扩展。您可以检查 php_mysql.dll 是否存在于<path to your php installation>/ext基于 Windows 的服务器的 php 扩展目录(最有可能)中。在 linux 中,您可以使用以下命令检查是否已安装。

yum list installed | grep php

It will list down all the php extensions installed.

它将列出所有已安装的 php 扩展。