Anastasie Laurent Anastasie Laurent - 2 years ago 1014
SQL Question

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

I am using Laravel to connect to MySQL database.

I got this exception:

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
database? and why the
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

Update 2

I wrote this in my Route

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

and I added
in my controllers folder

and inside
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

I am using Windows 7 with Laravel 4.2

Thanks in advance

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download