【发布时间】:2021-11-27 00:46:14
【问题描述】:
我想在 Laravel 视图中显示我的 MySQL 数据库的所有表。
但是当我打开网站时,会无休止地加载页面。
我该如何解决?
路线:
<?php
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\DB;
Route::get('/', function () {
return view('welcome');
});
Route::get('/listen', function () {
$groups = DB::select('SHOW TABLES');
return view('listen', ['groups' => $groups]);
});
需要显示表格的页面:
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
<title>ListenOnce - Homepage</title>
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700&display=swap" rel="stylesheet">
</head>
<body class="bg-dark">
<div id="app">
<h1 class="display-1 text-center" style="color: #8800e7; margin-top: 50px">Browse groups</h1>
@foreach($groups as $group)
<div>
{{ $group->group_name }}
</div>
@endforeach
</div>
<script src="{{ mix('/js/app.js') }}"></script>
</body>
</html>
数据库配置:
<?php
use Illuminate\Support\Str;
return [
'default' => 'mysql',
'connections' => [
'mysql' => [
'read' => [
'host' => [
'127.0.0.1'
],
],
'write' => [
'host' => [
'127.0.0.1'
],
],
'sticky' => true,
'driver' => 'mysql',
'database' => 'listenonce',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'port' => '8080'
],
],
];
我试图等待,并给出“超过 60 秒的最大执行时间”错误。
我没有使用默认的 .env 文件。
我该如何解决?
我是 Laravel 和 MySQL 的新手。
提前致谢!
【问题讨论】:
-
您是否对您的代码进行过任何调试?在我看来,简单的第一步是路由定义中的
dd($groups);。 -
为什么
MySQL有端口8080?应该是3306...8080用于 HTTP。 -
此外,你甚至不应该使用网络访问 MySQL,它应该被禁用并使用本地套接字。
标签: php mysql laravel database