[英]Kohana: Connecting to database and executing a query
我本打算在他們的論壇上發布此消息,但目前他們似乎不高興。
$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)我有點困惑,因為根據他們的教程,execute($ 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,
),
);
數據庫:: instance('mydb');
這不是數據庫名稱,而是數據庫配置組。 檢出數據庫配置文件以了解其結構。
您可以發布您的配置文件嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.