Laravel 8-找不到驱动程序:IlllightateDatabaseQueryException找不到驱动程序(SQL:SELECT*FROM`list`)
我已经在我的Linux Mint20上安装了Laravel 8作为我的个人实验,所以我对Laravel的新版本还是个新手。我已经寻找了很多源码,如何用CRUD方法显示表格,使表格在Web上显示包含MySQL数据库中的数据
但当我尝试使用CRUD方法显示表格时,结果如下所示:
IllLumateDatabaseQueryException异常 找不到驱动程序(SQL:SELECT*FROM
list
)
在本地主机:8000/home/tabel
我尝试通过修复.env文件、控制器文件、刀片文件和web.php来解决此问题,但仍然错误。
这是我的配置文件,我将其更改如下:
.env
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=people
DB_USERNAME=root
DB_PASSWORD=
home Controller.php
<?php
namespace AppHttpControllers;
use IlluminateHttpRequest;
use IlluminateSupportFacadesDB;
class homeController extends Controller
{
public function home()
{
return "home";
}
public function tabel()
{
$tabelku = DB::table('list')->get();
return view('tabel', ['people' => $tabelku]);
}
}
tabel.blade.php
<!DOCTYPE html>
<html>
<head>
<title>Table</title>
</head>
<body>
<div align="center">
<table border = "1">
<tr>
<th>No</th>
<th>Name</th>
<th>Age</th>
<th>Hobby</th>
</tr>
@foreach($tabelku as $t)
<tr>
<th>{{$t->no}}</th>
<th>{{$t->name}}</th>
<th>{{$t->age}}</th>
<th>{{$t->hobby}}</th>
</tr>
@endforeach
</table>
</div>
</body>
</html>
然后是web.php
<?php
use IlluminateSupportFacadesRoute;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('welcome');
});
Route::get('/hello', function () {
return 'Halo Dunia';
});
Route::get('/home','homeController@home');
Route::get('/home/tabel','homeController@tabel');
这是我用来显示CRUD方法中的表的数据库和表->;
对于MySQL数据库,我使用XAMPP
有人能解释为什么这是错误并给我解决方案吗?我应该做些什么来修复它?
解决方案
只需安装适用于php-mySQL的驱动程序:
# default
sudo apt install php-mysql
# for specific version of php (e.g. php7.4)
sudo apt install php7.4-mysql
重新启动服务器:
# apache
sudo systemctl restart apache2
# nginx
sudo systemctl restart nginx
相关文章