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

时间:2015-04-02 01:11:50

标签: mysql cakephp

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

  

CakePHP无法连接到数据库。

     

数据库驱动程序Cake \ Database \ Driver \ Mysql因a而无法使用   缺少PHP扩展或未满足的依赖

我的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

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,

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

5 个答案:

答案 0 :(得分:10)

运气解决了这个问题!:

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

答案 1 :(得分:8)

安装modules for MySQL database connections为我解决了这个问题:

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

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

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

答案 2 :(得分:4)

错误消息是因为extension = php_pdo_mysql.dll未安装和启用php.ini。如果未启用php_intl.dll,则在检查数据库连接之前会出现错误。

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

答案 3 :(得分:1)

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.

yum list installed | grep php

It will list down all the php extensions installed.

答案 4 :(得分:0)

试试这个:

对于PHP 7.0

sudo apt-get install php7.0-mysql

对于PHP 5:

sudo apt-get install php5-mysql