简体   繁体   English

Kohana-Database_Exception [2]:mysql_connect()

[英]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. 我正在运行Kohana v3.2,我只是尝试使用小型MVC来启动并运行,因此建议使用此系统。 I'm following this tutorial: http://kowsercse.com/2011/09/04/kohana-tutorial-beginners/ 我正在关注本教程: 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还是很陌生,对Kohana还是很陌生,但是从错误中猜测,ORM尝试使用用户名ODBC访问我的数据库,但是到目前为止,我还没有在我创建的页面/文件中的任何位置定义它。我位于的database.php配置: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. 我可以想象您已经安装了ODBC / Connector-它是一个数据库驱动程序,它会以默认用户的身份创建自己( ODBC )。 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. 因为您没有在配置中指定用户(并且您也没有,因为您有错字;),所以默认情况下它将尝试与ODBC连接。

If you correct line 8 of your database configuration file, all should start to work correctly. 如果您更正了数据库配置文件的第8行,则所有文件都应开始正常工作。

...

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

Oh, and unless you have your hosts file set up weirdly; 哦,除非您怪异地设置了hosts文件,否则, 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. 您应该能够使用localhost而不是127.0.0.1没有什么区别(除了localhost不管您使用的是IPv4还是IPv6都可以工作),它可能更易于读取/键入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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