Cake is NOT able to connect to the database - php

I am using Wamp server and I'm trying to install CakePHP 2.0.0 but I'm having trouble with it.
I put the CakePHP 2.0.0 files in my wamp server folder "www" and then "cake" folder.
When I enter address http://localhost/cake in my browser then following message is displayed:
CakePHP: the rapid development php framework
Release Notes for CakePHP 2.0.0-dev.
Notice (1024): Please change the value of 'Security.salt' in app/config/core.php to a salt value specific to your application [CORE\Cake\Utility\Debugger.php, line 647]
Notice (1024): Please change the value of 'Security.cipherSeed' in app/config/core.php to a numeric (digits only) seed value specific to your application [CORE\Cake\Utility\Debugger.php, line 651]
Your tmp directory is writable.
The FileEngine is being used for caching. To change the config edit APP/config/core.php
Your database configuration file is present.
Cake is NOT able to connect to the database.
Editing this Page
To change the content of this page, create: APP/views/pages/home.ctp.
To change its layout, create: APP/views/layouts/default.ctp.
You can also add some CSS styles for your pages at: APP/webroot/css.

I had the same problem and it took a lot of researching to determine the actual problem.
The new version of CakePHP uses pdo to establish a connection rather than mysql or mysqli as it did previously. As you are using a Windows environment, just enable the following in php.ini file.
extension=php_pdo_mysql.dll
NOTHING to do with using root and I also found it an real annoyance when trying to move from 1.3 to 2.0
As for the arrogant answer from deceze, I found NO mention of this change anywhere on the CakePHP download / install / docs.

I can't upvote due to a lack of reputation, however I'd like to point out that despite the comments under your question (which, in part, are correct), George Wood is exactly correct: you need to enable
extension=php_pdo_mysql.dll (Windows)
or for me it was extension=pdo_mysql.so (Arch Linux)
...and there may be some variants out there too. I've just struggled with this for an hour. Best of luck with your coding efforts.

My problem with cakephp was solved on Ubuntu by doing this:
sudo apt-get install php5-mysql
sudo /etc/init.d/apache2 restart
I'm using Ubuntu 10.04, MySQL, Apache2 and PHP5.
Once I did that I could use the MySQL user I created. So it wasn't a cakephp config error it was not knowing php5-mysql was not installed by default.

They are NOT errors, they are notices. This means you can do some configurations in order to make it work. Read over them and do what they tell you to do. Seems like errors happen in your config/, watch out to provide correct information such as database's name and password.
Edit
Just to answer your question, CakePHP is a PHP framework that assist you with constructing your website in MVC model. Instead writing source code from scratch, by using framework, you can inherit all its functionality that speed up your development time, help you to deal with more-complex structure/procedures more easily.

If you haven't still solved the connection issue with database, try doing a sanity check on these bits..
'driver' (ok in 1.3) has been renamed to 'datasource'
'mysql' (ok in 1.3) has to be specified as 'Database/Mysql'
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'root',
'password' => '',
'database' => 'sandbox',
'prefix' => '',
'encoding' => 'utf8');
Let me know if this worked.
(I was trying to reuse my old 1.3 config and got caught in the same loop.)

Please find solution as shown below.
Notice (1024): Please change the value of 'Security.salt' in app/config/core.php to a salt value specific to your application [CORE\Cake\Utility\Debugger.php, line 647]
Solution: Go thorough this file app/config/core.php
find Security.salt and change it to any value.
Notice (1024): Please change the value of 'Security.cipherSeed' in app/config/core.php to a numeric (digits only) seed value specific to your application [CORE\Cake\Utility\Debugger.php, line 651]
Solution: Go thorough this file app/config/core.php
find Security.cipherSeed and change it to any value.
Your tmp directory is writable.
Solution: Give proper permission for this path app/tmp
Cake is NOT able to connect to the database.
Solution: Go thorough this file app/config/database.php
set proper parameters for database connection.

Just adding this in here... I came across this (and other similar solutions) but only recently found the problem. I had an issue with my custom Apache build due to other software issues and decided to quickly get a working environment rather than reformat my PC.
I first installed Apache 2.4 and PHP 5.4. These versions were unfortunately incompatible with most of my code, and again, I wanted to quickly get a working environment, so I uninstalled and went back to WAMP with Apache 2.2 and PHP 5.3.
At some point, WAMPServer was looking at C:\Program Files (x86)\PHP\php.ini for my php.ini file. I do not know how or why it was looking there. Unfortunately I was editing C:\wamp\bin\php\php5.3.13\php.ini instead. I didn't realize why MySQL wasn't working until I loaded up a call to phpinfo() and noticed PHP was looking in the "wrong" place for my php.ini.
In case anyone else has a similar issue, I figured I'd add it here to the mix. Good luck!

I had the same problem and I figured it out.
I had the wrong username and password for database connection.
So I opened database and edited the database.php file. Now cake is able to connect to the database.

Recently I had the same problem with xampp installed on a windows machine, for me it was because when entering the details
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
windows could not resolve localhost to being 127.0.0.1, this can be solved by one of either solutions:
Change details in app/Config/database.php to
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => '127.0.0.1',
Or edit in windows C:\Windows\System32\drivers\etc\hosts (You may need to run Nopepad.exe as administrator to do this)
add a line at the end with:
127.0.0.1 localhost

I solved this error by downgrading my xampp from version 7.0 to version 5.6. Seems that the updated xampp doesn't support the cakeframework perfectly. I used this trick to also succesfully install orangescrum.

On local host for mysql, it is compulsory to use the user "root" rather than any other user. Hope this helps.
Also check this.

Related

cURL error 60: SSL certificate in Laravel 5.4

Full Error
RequestException in CurlFactory.php line 187: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
Scenario
Before anyone points me to these two laracasts answers: https://laracasts.com/discuss/channels/general-discussion/curl-error-60-ssl-certificate-problem-unable-to-get-local-issuer-certificate
https://laracasts.com/discuss/channels/general-discussion/curl-error-60-ssl-certificate-problem-unable-to-get-local-issuer-certificate/replies/52954
I've already looked at them and that's why I'm here.
The problem I have is that now I have the cacert.pem file BUT it doesn't make sense where to put it, the answers indicate to place the file in my xampp directory and change my php.ini file but I'm not using xampp for anything, I'm using Laravel's artisan server to run my project.
If xampp is not in use, where should I place this file? Moreover, why would an accepted answer be to place it in my xampp directory? I dont understand.
My Exact Question
Where do I place the cacert.pem file to stop this error in laravel 5.4?
Do not ever modify files in the vendor/ folder. Ever. They can and will be overwritten on the next composer update you run.
Here is my Solution for WampServer
I am using PHP 7.1.9 for my WampServer, so change 7.1.9 in the example below to the version number you are currently using.
Download this file: http://curl.haxx.se/ca/cacert.pem
Place this file in the C:\wamp64\bin\php\php7.1.9 folder
Open php.iniand find this line:
;curl.cainfo
Change it to:
curl.cainfo = "C:\wamp64\bin\php\php7.1.9\cacert.pem"
Make sure you remove the semicolon at the beginning of the line.
Save changes to php.ini, restart WampServer, and you're good to go!
A quick solution but insecure (not recommended).
Using cURL:
Set CURLOPT_SSL_VERIYPEER to false
Using Guzzle: Set verify to false, for example
$client->request('GET', 'https://somewebsite.com', ['verify' => false]);
You can use GuzzleHttp\Client:
$client = new Client(['verify' => false]);
Solution suggested by some users to make changes to \vendor\guzzlehttp\guzzle\src\Client.php file is the worst advice, as manual changes made to vendor folder are overwritten if you run composer update command.
Solution suggested by Jeffrey is a dirty, shorthand fix but not recommended in production applications.
Solution suggested by kjdion84 is perfect if you have access to php.ini file on web server. In case you are using Shared Hosting, it may not be possible to edit php.ini file.
When you don't have access to php.ini file (e.g. Shared Hosting)
Download this file: http://curl.haxx.se/ca/cacert.pem or https://curl.se/docs/caextract.html
Place this file in the root folder of your Laravel project.
Add verify key to GuzzleHttp\Client constructor with its value as path to cacert.pem file.
With Laravel 5.7 and GuzzleHttp 6.0
// https://example.com/v1/current.json?key1=value1&key2=value2
$guzzleClient = new GuzzleHttp\Client([
'base_uri' => 'https://example.com',
'verify' => base_path('cacert.pem'),
]);
$response = $guzzleClient->get('v1/current.json', [
'query' => [
'key1' => 'value1',
'key2' => 'value2',
]
]);
$response = json_decode($response->getBody()->getContents(), true);
This was stressfull to figure out but here is the exact answer for people using laravel and have this problem.
My exact application versions are...
Laravel: 5.4
Guzzlehttp: 6.2
Laravel Socialite: 3.0
Download a fresh copy of this curl certificate from this link: https://gist.github.com/VersatilityWerks/5719158/download
Save the file in this path starting from the base root of your laravel application vendor/guzzlehttp/guzzle/src/cacert.pem
next in that same directory open up RequestOptions.php and scroll down to the constant called CERT and change it to this const CERT = 'cacert.pem'; and this should fix it all.
EDIT
As people are pointing out you should never edit the vendor folder, this was just a quick fix for an application I was building in my spare time. It wasn't anything majorly important like an application for my company or anything, use this method at your own risk! Please check out the other answers if you need something more concrete.
I was sending a request from domain X to Y, my problem was with the certificate used on the domain Y (it wasn't a self-signed cert btw), the domain belonged to me & I had the certificate, so the quick fix was to use the domain Y's certificate on domain X's application:
On domain X:
Using Laravel 7 HTTP wrapper:
\Http::withOptions(['verify' => 'path-to-domain-Y-certificate']);
Using guzzle:
new GuzzleHttp\Client(['verify' => 'path-to-domain-Y-certificate']);
OR you could just contact your SSL provider to resolve the issue.
Note: Storing your domain's certificate in another system isn't a secure method, use this method only if you can ensure your certificate's security.
I haven't found what was wrong with the certificate, no browser seemed to have a problem with it, the only problem was generated on laravel using curl.
I had this problem while running Valet and attempting to make an api from one site in valet to another.
Note that i'm working in OSX.
I found the solution here: https://github.com/laravel/valet/issues/460
In short you have to copy the valet pem to the system CA bundle.
Just run this:
cp /usr/local/etc/openssl/cert.pem /usr/local/etc/openssl/cert.pem.bak && cat ~/.config/valet/CA/LaravelValetCASelfSigned.pem >> /usr/local/etc/openssl/cert.pem
I use laragon server and I faced to the same problem. I downloaded ssl certificate from http://curl.haxx.se/ca/cacert.pem and paste it in C:/laragon/etc/ssl/
(if cacert.pem already exists replace it with new one).
restart server and everything is fine
We can set path based on this article on Medium.com How to fix cURL error 60: SSL certificate problem
Steps to follow:
Open http://curl.haxx.se/ca/cacert.pem
Copy the entire page and save it as a “cacert.pem”
Open your php.ini file and insert or update the following line. curl.cainfo = " [pathtofile]cacert.pem"
Another one recently asked for the same problem and it's seems my answer was the solution for him.
Here was the post I mention : URL Post
That's what I said :
I'll be fully honest, I don't know anything about Laravel. But I had
the same problem, so as many other, on Symfony. And so as you I tried
many things without success.
Finally, this solution worked for me : URL solution
It indicates that instead of a certificate problem, it could came
from a environnement non-compatibility. I used XAMPP instead of
WAMP and it worked.
Solved it on my end by disabling verify completely when on debug setting since in this local scenario security is not an issue at all.
$http = new \GuzzleHttp\Client([
'base_uri' => config('services.passport.login_endpoint'),
'verify' => config('app.debug') ? false : true,
'defaults' => [
'exceptions' => false,
]
]);
curl.cainfo = "C:\wamp64\bin\php\php7.1.9\cacert.pem"
I had resolved my problem with wamp.
This happened to me in development with laravel 8 using the default server started by running:
php artisan serve
The solution for me was similar to other answers that require you to download cacert.pem and edit php.ini file. But since I was not using Wamp, I checked the path in my environment variables to find which php installation windows defaulted to and made the changes there.
For php version ^8.1 in wampserver
Download--> https://curl.se/ca/cacert.pem.
Place the cacert.pem file inside C:\wamp64\bin\php\php8.1.0.
Open php.ini and find this line:
;curl.cainfo
Change it to:
curl.cainfo = "C:\wamp64\bin\php\php8.1.0\cacert.pem"
Make sure you remove the semicolon at the beginning of the line.
Save changes to php.ini, restart WampServer64, and you're good to go!
You need to edit the following file in vendor/guzzlehttp/guzzle/src/Client.php
$defaults = [
'allow_redirects' => RedirectMiddleware::$defaultSettings,
'http_errors' => true,
'decode_content' => true,
'verify' => false, // By default this value will be true
'cookies' => false
];
May be security issue was there, but it will work.
for Laravel: The 5 steps below will be helpful
update version to Guzzlehttp: 5.2
find the file under \vendor\guzzlehttp\guzzle\src\Client.php
edit default settings to
protected function getDefaultOptions() {
$settings = [
'allow_redirects' => true,
'exceptions' => true,
'decode_content' => true,
'verify' => getcwd() .'/vendor/guzzlehttp/guzzle/src/cacert.pem'
];
}
download latest file cacert.pem from http://curl.haxx.se/ca/cacert.pem and place under /vendor/guzzlehttp/guzzle/src/

Configure Cakephp 2.6.0 with Redis Engine

I am trying to configure cakephp ver 2.6.0 to use redis engine by default. but somehow i am not able to make it work. any help will be highly appreciated.
Things Which i have tried so far..
Configured app/config folder 2 files , core.php and bootstrap.php. , according to the guidelines provided here in this blog configure cake with redis and this blog too Another cake-redis config setup
but i keep on getting errors like.
Fatal error: Uncaught exception 'CacheException' with message 'Cache engine session is not properly configured.' in C:\wamp\www\project\cakephp\cakephp_2.6.0\lib\Cake\Cache\Cache.php on line 181
CacheException: Cache engine session is not properly configured. in C:\wamp\www\project\cakephp\cakephp_2.6.0\lib\Cake\Cache\Cache.php on line 181
Any help will be highly appreciated.
I was having the same exact issue today while trying to setup CakePHP to use Redis as the cache engine.
Coincidentally, I also read the same setup instructions from the two blogs you linked to.
The reason was that I had copied pasted the Configure::write(...) code block from the Another cake-redis config setup blog post as it is and pasted it into the file without first commenting out the Configure::write(...) code block that was already in the core.php file.
I'm assuming that you have already successfully setup Redis on Windows and have installed the PHPRedis extension without any issues.
I am using the instructions from Another cake-redis config setup here.
In your app/Config/core.php file, comment out the following block: (this was starting at line 218 in my core.php)
Configure::write('Session', array(
'defaults' => 'php'
));
Instead, you can put this in: (You can change the values to suit your particular needs)
Configure::write('Session', array(
'defaults' => 'cache',
'timeout' => 100,
'start' => true,
'checkAgent' => false,
'handler' => array(
'config' => 'session'
)
));
After this, change the value of $engine to 'Redis', so it becomes:
$engine = 'Redis';
And then, put this code in, I put this in at the very end of the file: (Again, your values can be different depending on what your setup is)
Cache::config ('session', array (
'Engine' => $engine,
'Prefix' => $prefix . 'cake_session_',
'Duration' => $duration
));
And that's it. You're done! No need to change anything else.
To make sure that Redis is working properly with CakePHP, I ran the RedisEngine Test Suite that comes with CakePHP. You need to have PHPUnit installed for this to work.
It can be accessed via http://your-cakephp-project/test.php
Click on 'Tests' under Core and then click on 'Cache/Engine/RedisEngine'
If everything is working successfully, you should see all the tests pass.
Alternatively, you can use redis-cli at the command prompt to confirm that Redis is storing keys properly.
Once you have logged in by typing redis-cli, type KEYS *
This should give you a list of keys related to your CakePHP setup.
An example would be the "myapp_cake_core_object_map" key.
Hope this helps.

Laravel 4.2 says my application is in production. How do I turn this off?

I have a fresh install of Laravel. When running php artisan migrate:refresh I get a message saying Application In Production! Do you really wish to run this command?'
I know this is an update in 4.2, however I can't figure out how to turn it off.
I found in the source that it comes from Illuminate\Console\ConfirmableTrait and runs if this if test passes : if ($this->getLaravel()->environment() == 'production')
I'm not sure why it thinks I'm in production. I never setup any environments. This is the default environment detection, which I'm still currently using.
$env = $app->detectEnvironment(array(
'local' => array('homestead')
));
Also, if I set a production environment to a hostname that isn't my machine, I still have the same problem.
Just specify a machine name for the host that matches a given environment, then laravel will automatically detect the environment (default is production), for example:
$env = $app->detectEnvironment(array(
//'local' => array('homestead'),
'local' => array('*.dev', gethostname()),
'production' => array('*.com', '*.net', 'www.somedomain.com')
));
Read the documentation and this answer as well.
Setting your environment to something other than production is The Right Way. See the accepted answer.
But, if you're looking for A Quick Fix you can use (in UNIXoid environments):
yes | php artisan migrate:refresh
All this does is send a stream of "y" to the program, which acts like you pressed "y" when prompted.
I find this to be a little better than --force, as not all the artisan commands support force.
In case if anyone stumbled upon this question while searching for similar problem in a lumen installation I'd suggest to check the .env file and add APP_ENV=local if its not already there. It solved my problem.
Hopefully this will help someone else. I suddenly had an issue where my dev site I was building stopped connecting to the DB saying:
PDOException SQLSTATE[HY000] [1049] Unknown database 'forge' failed
I was also receiving errors such as the OP when trying to run artisan migrate:refresh etc, the error was stating that i was in production etc etc.
After much head scratching (!) I found that my hostname value set inside the /bootstrap/start.php was wrong, because my hostname had changed on my macbook pro!? I have no idea how but it changed from something like RobMacbookPro2.local to RobMacbookPro.local. This meant it fell back to production thus loading the incorrect database.php file with the standard DB=forge (which was wrong)
Check this guide:
http://laravel.com/docs/4.2/configuration
Pay particular attention to the code:
<?php
$env = $app->detectEnvironment(array(
'local' => array('your-machine-name'),
));
On a mac and probably linux? you can determine your hostname by typing # hostname in terminal.
Hope that saves someone some time!

Odd issue with CakePHP Document Root

Ok, here's a new one to me.
Here's the situation... I have a Cake app running under multiple environments (dev, qa, staging, live), managed using GIT.
I'm developing away on my development branch, and access that branch from dev.BLAH.com.
DEV is served out of /var/www/dev.BLAH.com/app
Occasionally, when working on DEV I start getting errors like this:
Warning (512): Model "Exercise" is not associated with model "ExerciseOutcome" [/var/www/QA.BLAH.com/lib/Cake/Model/Behavior/ContainableBehavior.php, line 344]
NOTE: That error is caused because it is trying to find an association
that is not built yet under the QA environment, so it's not about the missing association, it's about the WRONG PATH.
Clearly, for some unknown reason, the DEV domain is trying to serve files from the QA domain! Now, I don't think this is related to some kind of human coding error, because the simple FIX for it is to restart Apache!
Now, I thought it might be some kind of session issue, because I'm storing sessions in the DB, but even if I clear all the sessions in the DB (without restarting apache), it doesn't fix it.
But if I restart Apache, leaving the sessions table untouched, it suddenly starts working again!
It all seems so strange to me, that I just don't know where else to look.
I tried changing the various levels of caching, but that didn't change anything.
I don't think I'm an idiot, but I hope someone can prove me wrong! ;)
As noted in the comments, the issue is most likely to do with APC and prefixes.
What happens is that Cake caches the paths of various models using APC. This is all fine until you have multiple applications that use the same cache data on the one server. This is why Cake allows you to set the prefix of the cache.
So one solution is to set the prefix in a per-deployoment basis, like this:
// Prefix each application on the same server with a different string, to avoid Memcache and APC conflicts.
$prefix = 'myapp_DEV_';
However, this gets messy when you're using source control and you want the various deployments to be as close to each other as possible.
The way I got around it was to modify the cache config in APP/Config/core.php as follows:
/**
* Configure the cache used for general framework caching. Path information,
* object listings, and translation cache files are stored with this configuration.
*/
Cache::config(
'_cake_core_',
array(
'engine' => $engine,
'prefix' => $prefix . 'cake_core_' . Inflector::slug(ROOT),
'path' => CACHE . 'persistent' . DS,
'serialize' => ($engine === 'File'),
'duration' => $duration
)
);
Note the Inflector::slug(ROOT) line. This will give each application a unique prefix, without having to explicitly set it.

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

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 error:
Cake is NOT able to connect to the database. Database connection
"Mysql" is missing, or could not be created.
When I run this helpful code in my home.ctp, I get the following response:
Error!: SQLSTATE[42000] [1049] Unknown database 'test'
However, my Users/Ben/Sites/myapp/app/Config/database.php looks like this (I set MAMP to look for the document root in Users/Ben/Sites):
<?php
class DATABASE_CONFIG {
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'Ben',
'password' => 'mypass',
'database' => 'CV',
);
}
I have created a mysql user called Ben with password mypass and created a database called CV under that. Moreover, I can't find mention of a test database anywhere. Help?
Try adding the socket:
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
An alternative to unix_socket (especially for OS X people) is to replace localhost with 127.0.0.1
Would be as Follows :
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => '127.0.0.1',
'login' => 'user',
'password' => 'password',
'database' => 'database-name',
'prefix' => '',
'encoding' => 'utf8',
);
Edit php.ini and add:
extension=php_pdo_mysql.dll
Then restart your web server
On Mac, using MAMP as a development platform, for cake the correct solution is using Domingo Casarrubio solution.
Add the unix_socket parameter to your database configurations.
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
This error can also be caused if your connecting database user doesn't have the proper privileges. I believe you only need a minimum of INSERT, SELECT, UPDATE, and DELETE.
Always check username/password and the user privileges first since CakePHP will most likely give a vague database connection error for either.
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.
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 (note the change from single to double quotes):
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.
I have had this problem since upgrading to OSX Yosemite and inserting following line did the trick for me:
'unix_socket' => '/tmp/mysql.sock'
It can be that mysql PDO support is missing.
as root (or using sudo):
apt-get install php5-mysql
Just to help Ubuntu users out:
I had the same error in my ubuntu 13.10 machine with the newest xampp downlaoded directly from apachefriends. Tried most of the stuff in every post I could find about this error, but not the mac-specific stuff.
In the end, the fix happened to be the same as the elected answer here:
Find the socket that mysqld creates for programs to connect to:
user#host /opt$ find . -name mysql.sock
/opt/lampp/var/mysql/mysql.sock
add it to your cakePHP database configuration file (cakePHP)/app/Config/database.php
'unix_socket' => '/opt/lampp/var/mysql/mysql.sock'
To me, this finally resulted in my cake commands being able to be executed without the "Error: Database connection "Mysql" is missing, or could not be created.".
Because, cake bake use unix socket for connecting to database
so that you need add unix_socket for connection string.
You have to confirm location that store mysql.sock in WAS
Example: in my case i'm using xampp on MACOS 10.11
(edit file Config/database.php)
public $default = array(
‘datasource’ => ‘Database/Mysql’,
‘persistent’ => false,
‘host’ => ‘localhost’,
‘login’ => ‘root’,
‘password’ => ‘root’,
‘database’ => ‘cakephp’,
‘encoding’ => ‘utf8’,
‘unix_socket’ => ‘/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock’
);
Finally, It's work for me!
What did it for me in the end was that I had created a table in my database, but there was no data in it.
In order for CakePHP to recognize the MySql connection, there has to be a table with data in it.
You might need to create the table in your php file... Open up phpMyAdmin and check to ensure that they database CV exists.
It's your model. Open that up and there must be the following line
public $useDbConfig = 'local';
This overwrites global config & set it back to local
I tried splicing the code from Example 2 of http://php.net/manual/en/pdo.connections.php into /app/View/Pages/home.ctp. I had to fix the arguments the PDO constructor and change the name of the table in the query. The example 2 code returned the error "Error!: could not find driver". Based on King Jk's answer I was attempting to modify the php.ini when I started to wonder where a php_pdo_mysql.so might live. http://php.net/pdo_mysql showed how it was compiled as part of PHP via the --with-pdo-mysql option to configure. Recompiling fixed my problem. Note I'm working on a Ubuntu 12.10 system with PHP 5.5.9 and Apache Webserver 2.4.6
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).
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:
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.
If you're on Godaddy (or any other shared hosting for that matter), they may be limiting outgoing connections to ports 80 and 443 only.
System configuration:
Fedora 32
php-fpm 7.4.13
mariadb 10.4.17
CAKE 2.10.17
Error message from CAKE:
Database connection "Mysql" is missing, or could not be created.
Enhanced error message using answer at https://stackoverflow.com/a/24722976/5025060
Database connection "Mysql" is missing, or could not be created: Selected driver is not enabled
My problem was no "connector" between PHP and SQL was installed. The solution was:
dnf install php-mysqlnd
This allowed PHP to connect to the database as specified in CAKE's database.php configuration file.

Categories