Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am using Laravel to connect to MySQL database.

I got this exception:

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

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'    => '',
        ),

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

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

Update 1

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

Update 2

I wrote this in my Route

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

and I added UsersController.php in my controllers folder

and inside UsersController.php I have this:

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'));
    }

and I call this url http://localhost:8082/laravel/public/users/

I am using Windows 7 with Laravel 4.2

Thanks in advance

like image 814
Anastasie Laurent Avatar asked Jun 09 '14 11:06

Anastasie Laurent


4 Answers

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

php artisan cache:clear

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

like image 140
Freelancer Avatar answered Nov 03 '22 08:11

Freelancer


  1. First you have to Create your related Database.
  2. Then:php artisan cache:clear
  3. Now run php artisan migrate:install

Hope your problem will get resolved.

like image 23
user5320639 Avatar answered Nov 03 '22 08:11

user5320639


Using phpMyAdmin (or whatever you prefer), I just created a database called "forge" and re-ran the php artisan migrate command and it all worked.

like image 8
Joey Garcia Avatar answered Nov 03 '22 06:11

Joey Garcia


write

php artisan config:cache 

in your terminal and it will be fixed

like image 5
salma muhamad Avatar answered Nov 03 '22 06:11

salma muhamad