2011-03-15 107 views
1

我試圖連接到Kohana 3中的數據庫,但它沒有連接。數據庫無法連接到Kohana 3

這是我想從我的模塊之一運行查詢:

$results = DB::select()->from('users')->where('verified', '=', 0)->execute(); 

這裏的the dump of the error

ErrorException [ Notice ]: Undefined property: Config_File::$default 
MODPATH\database\classes\kohana\database.php [67] 
if($config === NULL) 
{ 
    // Load the configuration for this database 
    // echo "<pre>"; 
    //die(print_r(unserialize(Kohana::config('database')))); 
    $config = Kohana::config('database')->$name; 
} 

if(!isset($config['type'])) 
{ 
    throw new Kohana_Exception('Database type not defined in :name configuration', 

我在應用以下配置設置/配置/數據庫。 php

<?php defined('SYSPATH') or die('No direct access allowed.'); 
return array 
(
    'default' => array 
    (
     'type'  => 'mysql', 
     'connection' => array(
      /** 
      * The following options are available for MySQL: 
      * 
      * string hostname  server hostname, or socket 
      * string database  database name 
      * string username  database username 
      * string password  database password 
      * boolean persistent use persistent connections? 
      * 
      * Ports and sockets may be appended to the hostname. 
      */ 
      'hostname' => 'localhost', 
      'database' => 'test', 
      'username' => 'root', 
      'password' => FALSE, 
      'persistent' => FALSE, 
     ), 
     'table_prefix' => '', 
     'charset'  => 'utf8', 
     'caching'  => FALSE, 
     'profiling' => TRUE, 
    ), 
    'alternate' => array(
     'type'  => 'pdo', 
     'connection' => array(
      /** 
      * The following options are available for PDO: 
      * 
      * string dsn   Data Source Name 
      * string username database username 
      * string password database password 
      * boolean persistent use persistent connections? 
      */ 
      'dsn'  => 'mysql:host=localhost;dbname=test', 
      'username' => 'root', 
      'password' => FALSE, 
      'persistent' => FALSE, 
     ), 
     /** 
     * The following extra options are available for PDO: 
     * 
     * string identifier set the escaping identifier 
     */ 
     'table_prefix' => '', 
     'charset'  => 'utf8', 
     'caching'  => FALSE, 
     'profiling' => TRUE, 
    ), 
); 

我在使用PHP 5.3.3的Windows XP上使用XAMPP 1.7.4

有沒有人有任何想法我做錯了什麼?

+0

其他不連接的頁面都很好,但? – random 2011-03-17 18:16:38

+3

show'var_dump(Kohana :: config('database'))'result – biakaveron 2011-03-17 20:41:26

回答

1

好像Kohana中找不到配置文件在所有...通常這個文件是在/modules/database/config/database.php

+0

我不認爲是這樣。 Kohana網站和其他博客建議將modules/database/config/datatbase.php複製到application/config/database.php,這就是我所做的。順便說一句,我也複製了模塊/數據庫/配置文件夾中的配置,但沒有運氣。 – Mahbub 2011-03-16 11:21:13