Kohana 3 中数据库无法连接

发布于 2024-10-21 18:36:34 字数 2838 浏览 5 评论 0原文

我正在尝试连接到 Kohana 3 中的数据库,但无法连接。

这是我试图从我的模块之一运行的查询:

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

这是 转储错误

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',

我在 application/config/database.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,
    ),
);

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

有谁知道我做错了什么?

I'm trying to connect to my database in Kohana 3 but it's not connecting.

This is the query I'm trying to run from one of my modules:

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

Here's 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',

I have the following config setup in application/config/database.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,
    ),
);

I'm using XAMPP 1.7.4 on Windows XP with PHP 5.3.3

Does anyone have any idea what I am doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

辞旧 2024-10-28 18:36:34

似乎 Kohana 根本找不到配置文件...通常该文件位于 /modules/database/config/database.php

Seems like Kohana cannot find the config file at all... Usually this file is at /modules/database/config/database.php

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文