我打算在他们的论坛上发帖,但他们现在似乎已经失望了。
$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,
),
);
答案 0 :(得分:1)
数据库::实例( 'MYDB');
这不是数据库名称,而是数据库配置组。查看数据库配置文件以了解它的结构。
您可以发布配置文件吗?