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

编程入门 行业动态 更新时间:2024-10-26 04:21:54
本文介绍了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?

我找到了这条线受保护的 $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')); }

我称这个网址为 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

更多推荐

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

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

发布评论

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

>www.elefans.com

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