CakePHP错误数据库未定义

时间:2012-11-11 18:12:53

标签: php mysql database cakephp

我在每个问题中搜索了一个答案,但没有找到! 当我输入localhost / cakephp时,这是错误:

Notice (8): Undefined index: datasource [CORE\Cake\Model\ConnectionManager.php, line 258]

另一个错误:

Cake is NOT able to connect to the database.

无法找到数据源类。

这是我在database.php中的配置:

<?php
class DATABASE_CONFIG {
var $default = array('driver' => 'mysql',
                 'persistent'  => false,
                 'database' => '',
                     'host'        => 'localhost',
                     'login'       => 'lorizz',
                     'password'    => 'reyxD22!',
                     'database'    => 'my_cakephp_project',
                     'prefix'      => '');

var $test = array('driver' => 'mysql',
                 'persistent'  => false,
                  'database' => '',
                     'host'        => 'localhost',
                     'login'       => 'lorizz',
                     'password'    => 'reyxD22!',
                     'database'    => 'my_cakephp_project',
                     'prefix'      => '');

}
?>

任何答案?

2 个答案:

答案 0 :(得分:2)

您需要删除变量中使用过两次的数据库 var $ default和var $ test

database.php中的配置应为:

<?php
class DATABASE_CONFIG {
var $default = array('driver' => 'mysql',
                 'persistent'  => false,
                     'host'        => 'localhost',
                     'login'       => 'lorizz',
                     'password'    => 'reyxD22!',
                     'database'    => 'my_cakephp_project',
                     'prefix'      => '');

var $test = array('driver' => 'mysql',
                 'persistent'  => false,
                     'host'        => 'localhost',
                     'login'       => 'user',
                     'password'    => 'password!',
                     'database'    => 'test_database_name',
                     'prefix'      => '');

}
?>

答案 1 :(得分:0)

只改变&#39;驱动程序&#39; =&GT; &#39; mysql&#39;,到&#39;数据源&#39; =&GT; &#39;数据库/ MySQL的&#39;,

<?php
class DATABASE_CONFIG {
public $default = array('datasource' => 'Database/Mysql',
                 'persistent'  => false,
                 'database' => '',
                     'host'        => 'localhost',
                     'login'       => 'lorizz',
                     'password'    => 'reyxD22!',
                     'database'    => 'my_cakephp_project',
                     'prefix'      => '');

public $test = array('datasource' => 'Database/Mysql',
                 'persistent'  => false,
                  'database' => '',
                     'host'        => 'localhost',
                     'login'       => 'lorizz',
                     'password'    => 'reyxD22!',
                     'database'    => 'my_cakephp_project',
                     'prefix'      => '');

}
?>