CakePHP Database connection “Mysql” is missing, or could not be created

后端 未结 18 1381
暖寄归人
暖寄归人 2020-11-30 11:05

There have been several other posts about this, but none of the answers seemed to work for me.

When I navigate to the CakePHP page on my local machine, there is one

相关标签:
18条回答
  • 2020-11-30 11:15

    It can be that mysql PDO support is missing.

    as root (or using sudo):

    apt-get install php5-mysql
    
    0 讨论(0)
  • 2020-11-30 11:16

    I noticed that you've had asked this an year ago, and most probably would've solved this by now. However, for those facing the same issues when attempting to install CakePHP on XAMPP, all you have to do is change the 'login' to 'root', i.e. the default login of XAMPP, and leave the 'password' as '', i.e. blank. The complete code in your database.php file should look like this:

    public $default = array(
        'datasource' => 'Database/Mysql',
        'persistent' => false,
        'host' => 'localhost',
        'login' => 'root',
        'password' => '',
        'database' => 'ckblog',//replace with your own database name
        'prefix' => '',
        //'encoding' => 'utf8',
    );
    

    That's it.

    0 讨论(0)
  • 2020-11-30 11:20

    You might need to create the table in your php file... Open up phpMyAdmin and check to ensure that they database CV exists.

    0 讨论(0)
  • 2020-11-30 11:20

    I've been struggling with this the whole weekend and finally solved it. Turns out that the php.ini is pointing to a non-existing "extensions dir". Create a phpinfo() file and look at the value of this field: extensions_dir

    I noticed that in the mamp php installed folder there is a no-debug-non-zts-20131226 folder, which is different from the value shown in the phpinfo(). What I did was to clone this folder and changed the name to the value of the phpinfo(). Probably you could modify the php.ini file but I didn't want to.

    I don't know if you solved your problem, but I'm posting this because my problem was different and google took me here, so I hope to help future googlers having a similiar issue.

    Hope this helps.

    0 讨论(0)
  • 2020-11-30 11:21

    I had the same problem and found out eventually that it was caused by CakePhp not accepting that I used a user with a password, even if that user was created in PHPMyAdmin. I had to use the user 'root' with no password.

    I found this out after making the following change to the file /lib/Cake/Error/exceptions.php.

    The original line:

    protected $_messageTemplate = 'Database connection "%s" is missing, or could not be created.';
    

    is changed into this instead:

    protected $_messageTemplate = "Database connection \"%s\" is missing, or could not be created:\n    %s";
    

    This will give you the reason for the problem so that you may change the cause properly.

    0 讨论(0)
  • 2020-11-30 11:21

    In my case it was because the database didn't exist. I expected running ./app/Console/cake schema create would create it but it did not. Creating it with create database <database name> in mysql did the trick (although I had already assigned privileges).

    0 讨论(0)
提交回复
热议问题