Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Kohana:连接到数据库并执行查询_Php_Kohana - Fatal编程技术网

Php Kohana:连接到数据库并执行查询

Php Kohana:连接到数据库并执行查询,php,kohana,Php,Kohana,我本来打算在他们的论坛上发表这篇文章的,但他们现在似乎不在了 $mydb = Database::instance('mydb'); $query = DB::select()->from('codes')->where('name', '=', 'PHP'); 1) 在使用我在database.php中定义的自定义数据库实例时,我看不到这一点。它总是使用默认值。我怎么知道 我得到一个错误,上面写着: mysql_connect(): Access denied for use

我本来打算在他们的论坛上发表这篇文章的,但他们现在似乎不在了

$mydb  = Database::instance('mydb');
$query = DB::select()->from('codes')->where('name', '=', 'PHP'); 
1) 在使用我在database.php中定义的自定义数据库实例时,我看不到这一点。它总是使用默认值。我怎么知道

我得到一个错误,上面写着:

mysql_connect(): Access denied for user ''@'localhost' (using password: NO) ~ MODPATH\database\classes\kohana\database\mysql.php [ 56 ]
2) 我有点困惑,因为根据他们的教程,执行($mydb)应该是不必要的。。。但我看到过一些帖子暗示这是真的。是哪一个

配置文件:

<?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'   => 'kohana',
            'username'   => FALSE,
            '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=kohana',
            'username'   => 'root',
            'password'   => 'r00tdb',
            'persistent' => FALSE,
        ),
        /**
         * The following extra options are available for PDO:
         *
         * string   identifier  set the escaping identifier
         */
        'table_prefix' => '',
        'charset'      => 'utf8',
        'caching'      => FALSE,
        'profiling'    => TRUE,
    ),
    'mydb' => array(
        'type'       => 'mysql',
        'connection' => array(
            'hostname'   => '127.0.0.1',
            'username'   => 'test',
            'password'   => 'test',
            'persistent' => FALSE,
            'database'   => 'mydb',
        ),
        'table_prefix' => '',
        'charset'      => 'utf8',
        'profiling'    => TRUE,
    ),

数据库::实例('mydb')

这不是数据库名称,而是数据库配置组。查看数据库配置文件以了解其结构


你能发布你的配置文件吗?

没错。。。数据库名称和配置名称相同。将使用我的配置文件更新…确定。。。这已经解决了。。。它是从错误的配置文件中提取的。:)