简体   繁体   中英

Kohana - Database_Exception [ 2 ]: mysql_connect()

I'm running Kohana v3.2 I'm just trying to get up and running with a small MVC and was recommended this system. I'm following this tutorial: http://kowsercse.com/2011/09/04/kohana-tutorial-beginners/

Everything seemed to be going well until I got down to the add new article section, I created the files but when I point my browser to the article/new controller/action I get this error:

Database_Exception [ 2 ]: mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Access denied for user 'ODBC'@'localhost' (using password: NO)

MODPATH\database\classes\kohana\database\mysql.php [ 67 ]

62      catch (Exception $e)
63      {
64          // No connection exists
65          $this->_connection = NULL;
66 
67          throw new Database_Exception(':error',
68              array(':error' => $e->getMessage()),
69              $e->getCode());
70      }
71 
72      // \xFF is a better delimiter, but the PHP driver uses underscore

I'm still new to PHP and very new to Kohana but guessing from the error the ORM is trying to access my database with the username ODBC yet I have not defined this anywhere in the pages/files I have created so far, here is my database.php config which I have located in: application/config

<?php defined('SYSPATH') or die('No direct script access.');

return array
(
    'default' => array
    (
        'type'          => 'mysql',
        'connetion'     => array
        (
            'hostname'      => '127.0.0.1',
            'database'      => 'kohana_blog',
            'username'      => 'root',
            'password'      => '',
            'persistent'    => FALSE,
        ),
        'table_prefix'  => '',
        'charset'       => 'UTF8',
        'caching'       => FALSE,
        'profiling'     => TRUE,
    )
);

Any ideas would be great thank you :)

I would imagine you have ODBC/Connector installed - it is a database driver, and it creates itself ( ODBC ) as the default user. Because you haven't specified a user in your configuration (and you haven't, because you have a typo ;)) it tries to connect with ODBC by default.

If you correct line 8 of your database configuration file, all should start to work correctly.

...

'type'          => 'mysql',
'connection'     => array
(
        'hostname'      => '127.0.0.1',
...

Oh, and unless you have your hosts file set up weirdly; you should be able to use localhost instead of 127.0.0.1 - not that there's any difference (apart from the fact that localhost will work regardless of whether you're using IPv4 or IPv6), it might just be easier to read/type.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM