Reputation: 763
I want to retrieve a data from the database table into a cakephp shell script.
I have tried with the below code but its not working.
Code :
App::import('Model', 'ModelName');
$this->ModelName = ClassRegistry::init('ModelName');
$result = $this->ModelName->find('all');
Error :
Database connection "Mysql" is missing, or could not be created.
I already search a lot in a google but I am not able to find any proper answer for it.
Please help me in this concern.
Upvotes: 0
Views: 792
Reputation: 1082
It can be configuration issue too, make sure your app/Config/database.php contains proper credentials. Probably change
127.0.0.1
for
localhost
and try.
Upvotes: 0
Reputation: 763
Yehhh... I found it...
In case anyone else faces this, it's a case of PHP not having access to the mysql client libraries. Having a MySQL server on the system is not the correct fix. Fix for ubuntu (and PHP 5):
sudo apt-get install php5-mysql
Upvotes: 1
Reputation: 3327
For CakePHP 2.x try:
$this->ModelName = ClassRegistry::getObject('ModelName');
if (!obj) {
App::import('Model', 'ModelName');
$this->ModelName = new ModelName();
}
Upvotes: 0