本文介绍了Laravel PDOException SQLSTATE [HY000] [1049]未知数据库'forge'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Laravel连接到MySQL数据库.

I am using Laravel to connect to MySQL database.

我遇到了这个异常:

PDOException
SQLSTATE[HY000] [1049] Unknown database 'forge'

这是我的config.database.php

and this is my config.database.php

'mysql' => array(
            'driver'    => 'mysql',
            'host'      => 'localhost',
            'database'  => 'laravel',
            'username'  => 'Anastasie',
            'password'  => 'A@Laurent',
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
        ),

为什么错误引用PDO数据库?以及为什么forge数据库名称?我已经改变了.

why is the error referring to PDO database? and why the forge database name? I have already changed it.

我应该做些什么来告诉Laravel我正在使用MySQL数据库吗?

Should I do anything to tell Laravel that I am using MySQL database?

我找到了这条线protected $table = 'users';在我的user.php文件中,我将其更改为protected $table = 'user';因为我数据库中的表是user而不是users

I found this lineprotected $table = 'users';in my user.php file and I have changed it toprotected $table = 'user'; because the table in my database is user not users

我是在我的路线上写的

Route::resource('users', 'UsersController');

,我在控制器文件夹中添加了UsersController.php

and I added UsersController.php in my controllers folder

UsersController.php里面,我有这个:

class UsersController extends BaseController {

    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index()
    {
        $users = User::all();
        return View::make('users.index', compact('users'));
    }

我将此网址称为http://localhost:8082/laravel/public/users/

我正在使用Windows 7和Laravel 4.2

I am using Windows 7 with Laravel 4.2

预先感谢

推荐答案

您必须像这样清除缓存(因为您的旧配置位于缓存文件中):

You have to clear the cache like that (because your old configuration is in you cache file) :

php artisan cache:clear

pdo错误来自Laravel使用pdo驱动程序连接到mysql

The pdo error comes from the fact Laravel use the pdo driver to connect to mysql

这篇关于Laravel PDOException SQLSTATE [HY000] [1049]未知数据库'forge'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 08:32