Cake php Datasource class MySQL could not be found

2020-07-23 03:03发布

问题:

I have ubuntu 10.04 on server. I am trying to set up the cake php project but it gives me following error

   Cake is NOT able to connect to the database.

   Datasource class MySQL could not be found.

I have searched lot on the web regarding it. my config file looks like this

  class DATABASE_CONFIG {

public $default = array(
    'datasource' => 'Database/MySQL',
    'persistent' => false,
    'host' => 'localhost',
    'login' => 'root',
    'password' => 'mypassword',
    'database' => 'dbname',
    'prefix' => '',
    //'encoding' => 'utf8',
);
 }

I checked that server has all the things set up to connect as PDO I have run following script and it works fine.

    $conn = new PDO('mysql:host=localhost;dbname=dbname', $username, $password);

Then further I have changed in Mysql.php file of cake php which is in the "lib\Cake\Model\Datasource\Database"

I tried to give static connection in Mysql.php but this also doesn't work. I did exit in the Mysql.php and seems like control of page is not getting here.

    $this->_connection = new PDO('mysql:host=localhost;dbname=dbname', $username, $password);
$this->connected = true;

Please do let me know if I am missing anything.

Thanks in Advance.

回答1:

Casing matters, it should be:

'datasource' => 'Database/Mysql'

And not:

'datasource' => 'Database/MySQL'


回答2:

Mysql is not a supported source try 'datasource' => 'Database/Sqlite',