我正在使用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 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
我是在我的路线上写的
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')); }我将此网址称为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:clearpdo错误来自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'
发布评论