4

我在每个问题中都搜索了这个问题的答案,但没有找到!这是我输入 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'      => '');

}
?>

有什么答案吗?

4

2 回答 2

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'      => '');

}
?>
于 2012-11-12T10:30:44.807 回答
0

只需将 'driver' => 'mysql', 更改为 'datasource' => 'Database/Mysql',

<?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'      => '');

}
?>
于 2014-10-29T14:35:40.707 回答