CakePHP is NOT able to connect to the database
Solution 1
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
Solution 2
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.
Solution 3
try to add the port in database.php archive.Like this:
'host' => '127.0.0.1:3306',
Works for me.
Admin
Updated on June 04, 2022Comments
-
Admin almost 2 years
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?!