cakephp hosting "Cake is NOT able to connect to the database." - php

beginner level stuff-
-i recently hosted my cakephp project on 000webhost.com
-it shows the cake homepage
-but at the same time shows
Cake is NOT able to connect to the database.
Datasource class a2952772 could not be found.
-i have tried editing root/app/config/database.php number of times.
-i have created mysql database on 000webhost.com
i guess there is some problem with
$datasource in
public $default = array(
'datasource' => '????',
'persistent' => false,
'host' => 'mysql11.000webhost.com',
'login' => '*****',
'password' => '*****',
'database' => 'db1',
'prefix' => '',
//'encoding' => 'utf8',
);
if anybody has hosted and configured databases on 000webhost.com ,plz help...

You need to specify a valid datasource, such as 'Database/Mysql'. Also check the CakePHP database configuration section.

Related

CakePHP Console Cron Database connection Error

I have a Webapp which is using the CakePHP 2.x framework. The main front-end works perfectly fine but I have some cron jobs which are run form the Cake Console. When I run these cron jobs I get the following error:
"Error: Database connection “Mysql” is missing, or could not be created"
There are several similar questions on SO (but none of the given solutions works for me. I have the following DB connection setup in the Cake config file and which works for the front-end:
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'xxxxx.com',
'login' => 'xxxxxx',
'password' => 'xxxxxxx',
'database' => 'goalarc-dev',
'prefix' => '',
'unix_socket' => '/var/run/mysqld/mysqld.sock'
);
I added the 'unix_socket' key after reading a similar solution. My server is running on AWS and so I opened:
/etc/mysql/my.cnf
And found the socket line as follows:
socket = /var/run/mysqld/mysqld.sock
However when I browse to 'var/run/mysqld' the folder is empty when I use the command "ls -l". This would suggest to me that somethig is mis-configured. How can I find the true and valid location of mysql.sock?
A.

Phalcon, Docker MySQL connection fails

So I have 3 docker containers, one with PHP+PhalconPHP, one with MySQL and another with the webserver. Now on my host system I can connect to the MySQL in the docker container and I can also connect with PDO using the following code
new PDO('mysql:host=mysql;port=1024;dbname=database', 'root', 'password');
But for some reason the phalcon framework is unable to connect to the MySQL database using the config.php file like so
return new \Phalcon\Config([
'database' => [
'adapter' => 'mysql',
'port' => 1024,
'host' => 'mysql',
'username' => 'root',
'password' => 'password',
'dbname' => 'database',
'charset' => 'utf8',
],
]);
In this case, for some reason I am getting a Can't connect to MySQL server on 'mysql' (111 "Connection refused) even though I am 100% sure I can actually connect (as proven before with the PDO connection). I also tried hardcoding the actual MySQL container ip address but no luck either.
Any ideas?
So it appeared to be kind of a stupid "mistake" but here's the solution.
Apparently when you use the Phalcon Developer Tools to scaffold your project, it does not initialize the database with the port configuration as it outright ignores it. You can easily fix this by going into the app/config/services.php file and changing the db service to also include the port configuration.
$connection = new $class([
'host' => $config->database->host,
'port' => $config->database->port,
'username' => $config->database->username,
'password' => $config->database->password,
'dbname' => $config->database->dbname,
'charset' => $config->database->charset
]);

Cakephp installation

I have installed cakephp 2.7.5 on xampp but when I run my application I get an error message >CakePHP is NOT able to connect to the database.
Database connection "Mysql" is missing, or could not be created.< I suspect that my mysql server is not properly configured and I have particular concerns over the PDO and pdo_mysql settings in the php.ini file. How do I enable them? (I am totally lost here)Thanks in advance.
You don't mention configuring the connection, so your problem is most probably that of a missing initial database configuration.
You will obviously need to create a database (and maybe a user with sufficient permissions in that DB) before you setup the configuration. Don't mess with PDO configuration in php.ini, it should run out of the box with XAMPP.
Rename file name from database.php.default to database.php .Create a database in mysql. Open the file and change your mysql login,password and database from default variable.Then run your application.
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'user',
'password' => 'password',
'database' => 'database_name',
'prefix' => '',
//'encoding' => 'utf8',
);

CakePHP WAMP - Database Mysql connection missing

I have scoured the web for an answer but as of now have been unsuccessful. I am attempting to connect CakePHP to a database. But I keep getting the same response:
CakePHP is NOT able to connect to the database.
Database connection "Mysql" is missing, or could not be created.
Here is part of my database.php file
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'root',
'password' => '',
'database' => 'cake',
'prefix' => '',
//'encoding' => 'utf8',
);
^I've also tried different host/login combinations based from the access privileges list in phpmyadmin.
I think one problem might be that Wampserver is finding the wrong php.ini file. It seems that it is loading the file at: "C:\Program Files (x86)\PHP\php.ini" instead of something under "C:\wamp...". How would I set it to point at the right file??
However, I had added the line "extension=php_pdo_mysql.dll" to both files and still no luck. Any help would be appreciated.
I had the exact same issue. There was no problem in the mysql database as it was accessible through phpMyadmin and other applications running on the server. The issue was caused due to the mysql port not mentioned alongwith the host. Append the port with the host like... 'host' => 'localhost:3307'.
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost:3307',
'login' => 'root',
'password' => 'mypass',
'database' => 'cake_todos',
'prefix' => '',
//'encoding' => 'utf8',
);
Now, how to know the mysql port? For that you need to go to the server configuration file.. e.g. the in my case it was the properties.ini file in the home directory of the wamp folder. Open the file and you will most probably find an entry like this:
mysql_port=3307
mysql_host=127.0.0.1
So, here it is, the mysql_port. Hope it helps.
First check there is database called cake in your localhost/phpmyadmin, and if that mysql use the username root and no password and also make sure you set php_mysql on the right php.ini file (extension=php_mysql.dll).
Second, if you think the problem is because of php.ini file location, you can set it:
go to your wamp folder (C:\wamp) and
under that folder you'll find wampmanager.ini file and
Find php.ini word in that file you'll get this kind of line
(Type: item; Caption: "php.ini"; Glyph: 6; Action: run; FileName: "notepad.exe"; parameters: "...path here...")and locate the path and set "C:/wamp/bin/apache/apache2.2.21/bin/php.ini"
please tell me (vote) if it works. I hope it helps.
Thanks

Cake is NOT able to connect to the database. XAMPP

I'm developing on XAMPP 1.8.1 and running into issues with CakePHP not being able to connect to the database. I've looked around a bit, and others have suggested making sure pdo is enabled, and it is. I know my database settings are correct. I've checked and rechecked them, but I'm still getting:
Cake is NOT able to connect to the database.
Database connection "Mysql" is missing, or could not be created.
I've set up CakePHP multiple times before, even with XAMPP, and I've never run into this issue.
My database settings are as follows:
public $default = array(
'datasource' => 'Database/MySQL',
'persistent' => false,
'host' => 'localhost',
'login' => 'cakeuser',
'password' => '*****',
'database' => 'cake',
'prefix' => '',
//'encoding' => 'utf8',
);
Any suggestions?
Check the output of your phpinfo (). Is there a row titled PDO drivers? What does it say?

Categories