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

编程入门 行业动态 更新时间:2024-10-26 06:38:01
本文介绍了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 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: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'

本文发布于:2023-10-26 01:17:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1528654.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库   SQLSTATE   Laravel   PDOException   forge

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!