沃梦达 / 编程问答 / php问题 / 正文

Laravel 8-找不到驱动程序:IlllightateDatabaseQueryException找不到驱动程序(SQL:SELECT*FROM`list`)

Laravel 8 - Could not find driver : IlluminateDatabaseQueryException could not find driver (SQL: select * from `list`)(Laravel 8-找不到驱动程序:IlllightateDatabaseQueryException找不到驱动程序(SQL:SELECT*FROM`list`))

本文介绍了Laravel 8-找不到驱动程序:IlllightateDatabaseQueryException找不到驱动程序(SQL:SELECT*FROM`list`)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的Linux Mint20上安装了Laravel 8作为我的个人实验,所以我对Laravel的新版本还是个新手。我已经寻找了很多源码,如何用CRUD方法显示表格,使表格在Web上显示包含MySQL数据库中的数据

但当我尝试使用CRUD方法显示表格时,结果如下所示:

IllLumateDatabaseQueryException异常 找不到驱动程序(SQL:SELECT*FROMlist)

在本地主机: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

这篇关于Laravel 8-找不到驱动程序:IlllightateDatabaseQueryException找不到驱动程序(SQL:SELECT*FROM`list`)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Laravel 8-找不到驱动程序:IlllightateDatabaseQueryException找不到驱动程序(SQL:SELECT*FROM`list`)

基础教程推荐