Laravel PDOException SQLSTATE[HY000] [1049] 未知数据库 'forge'

2022-01-08 00:00:00 php mysql laravel laravel-4

我正在使用 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?

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

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

我在我的路线中写了这个

I wrote this in my Route

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/

我正在使用带有 Laravel 4.2 的 Windows 7

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

相关文章