2
votes

I wanna study cakePHP and everything is configured correctly, except the problem in yellow color which follows.

'CakePHP is NOT able to connect to the database. Database connection "Mysql" is missing, or could not be created.'

I looked through google and tried everything to fix this problem but none worked. The Extension php_pdo_mysql is set, I also could connect to my database using phpMyAdmin and I tried testing my connection using the following code which connection is ok and extension pdo_mysql is loaded.

<?php 
$link = mysql_connect('localhost','root',''); 
if (!$link) { 
    die('Could not connect to MySQL: ' . mysql_error()); 
} 
echo 'Connection OK'; mysql_close($link); 
var_dump( extension_loaded('pdo_mysql') );
?> 

The database.php file under app/Config follows: (note: I tried localhost on hostname and didn't work too)

class DATABASE_CONFIG {

    public $default = array(
        'datasource' => 'Database/Mysql',
        'persistent' => false,
        'host' => '127.0.0.1',
        'login' => 'root',
        'password' => '',
        'database' => 'database_name',
        'prefix' => '',
        //'encoding' => 'utf8',
    );

    public $test = array(
        'datasource' => 'Database/Mysql',
        'persistent' => false,
        'host' => '127.0.0.1',
        'login' => 'root',
        'password' => '',
        'database' => 'test_database_name',
        'prefix' => '',
        //'encoding' => 'utf8',
    );
}

The server that I'm using is wamp and it's working fine, I mean everyting is in green color on it status.

Please, could someone help me?!

5
Are you setting the database name?Guillermo Mansilla
are you setting the username and password on the file you mentioned above?AKKAweb
When Guillemo Mansilla said about the database, I decided to create it through phpMyAdmin, and the problem was gone. I thought cakePHP used to create initial database for me if it didn't exist.ThiagoCoder
I was setting the database, I just hadn't create it, because I thought cake would be able to create it to me.ThiagoCoder

5 Answers

2
votes

According to this page you have to make sure that you have pdo_mysql enabled in PHP,

Edit file php.ini, and uncomment:

extension=php_pdo_mysql.dll
1
votes

try to add the port in database.php archive.Like this:

'host' => '127.0.0.1:3306',

Works for me.

1
votes

You'll have to check for a couple of things in your default database i.e. public $default array.

First of all, change your 'host' from '127.0.0.0' to 'localhost' [I know there really isn't any difference, still, give it a go and see what happens]

'host' => '127.0.0.1:3306',

Next, check whether your database name is correct and matches your MySQL database.

'database' => 'database_name',

If your MySQL database name is something else, then you'll get the error you've mentioned in your code. For instance, if your MySQL database name is 'test_db', you'll have to write like this:

'database' => 'test_db',

Remember, make all of these changes in your default database.

0
votes

I had the same problem. I found solution for myself.

In my case CackPHP couldn't found any extensions, because i mess to specify extension_dir path.

I have just added following line in my php.ini file, before defining of extensions.

extension_dir = "C:/php/ext" (You may have different path)

and restarted my apache server.

-1
votes

Solution IS just specify password like that in your database.php file : 'password' => 'root',