Kohana: Connecting to database and executing a query

Aximili

New Member
I was going to post this on their forum, but they seem to be down at the moment.\[code\]$mydb = Database::instance('mydb');$query = DB::select()->from('codes')->where('name', '=', 'PHP'); \[/code\]1) This doesn't appear to me using my custom database instance that I have defined in database.php. It always uses the default one. How can I tell?I get an error that says: \[code\]mysql_connect(): Access denied for user ''@'localhost' (using password: NO) ~ MODPATH\database\classes\kohana\database\mysql.php [ 56 ]\[/code\]2) I am a bit confused, because based on their tutorial, a execute($mydb) shouldn't be necessary... but I have seen posts suggesting that it is. Which one is it?Config file:\[code\]<?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, ),\[/code\]);
 
Back
Top