php - Laravel 连接 mysql 时出现问题

标签 php mysql laravel database-connection wampserver

我正在尝试使用 laravel php 框架连接到 mysql 数据库。

但我收到以下错误:

"Maximum execution time of 60 seconds exceeded"


Symfony\Component\Debug\Exception\FatalErrorException
…\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php
48

对此类问题的大多数回复都是为了增加执行时间,但就我而言,我只是尝试简单的插入查询。我认为错误是连接失败,并且查询未到达...

这是我的database.php配置文件:

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Default Database Connection Name
    |--------------------------------------------------------------------------
    |
    | Here you may specify which of the database connections below you wish
    | to use as your default connection for all database work. Of course
    | you may use many connections at once using the Database library.
    |
    */

    'default' => 'mysql',
    /*
    |--------------------------------------------------------------------------
    | Database Connections
    |--------------------------------------------------------------------------
    |
    | Here are each of the database connections setup for your application.
    | Of course, examples of configuring each database platform that is
    | supported by Laravel is shown below to make development simple.
    |
    |
    | All database work in Laravel is done through the PHP PDO facilities
    | so make sure you have the driver for your particular database of
    | choice installed on your machine before you begin development.
    |
    */

    'connections' => [

        'sqlite' => [
            'driver' => 'sqlite',
            'database' => env('DB_DATABASE', database_path('database.sqlite')),
            'prefix' => '',
        ],

        'mysql' => [
            'driver' => 'mysql',
            'host' => '127.0.0.1',
            'port' => '5000',
            'database' => 'valet',
            'username' => 'root',
            'password' => '123456',
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'strict' => true,
            'engine' => null,
        ],

        'pgsql' => [
            'driver' => 'pgsql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '5432'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'prefix' => '',
            'schema' => 'public',
            'sslmode' => 'prefer',
        ],

        'sqlsrv' => [
            'driver' => 'sqlsrv',
            'host' => env('DB_HOST', 'localhost'),
            'port' => env('DB_PORT', '1433'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'prefix' => '',
        ],

    ],

    /*
    |--------------------------------------------------------------------------
    | Migration Repository Table
    |--------------------------------------------------------------------------
    |
    | This table keeps track of all the migrations that have already run for
    | your application. Using this information, we can determine which of
    | the migrations on disk haven't actually been run in the database.
    |
    */

    'migrations' => 'migrations',

    /*
    |--------------------------------------------------------------------------
    | Redis Databases
    |--------------------------------------------------------------------------
    |
    | Redis is an open source, fast, and advanced key-value store that also
    | provides a richer set of commands than a typical key-value systems
    | such as APC or Memcached. Laravel makes it easy to dig right in.
    |
    */

    'redis' => [

        'client' => 'predis',

        'default' => [
            'host' => env('REDIS_HOST', '127.0.0.1'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', 6379),
            'database' => 0,
        ],

    ],

];

请注意,我正在端口 5000 上运行 wamp 服务器。

最佳答案

.envconfig/database.php 中进行更改(设置数据库端口)。

确保运行 php artisan config:cache 来清除并缓存 Laravel 的配置。

关于php - Laravel 连接 mysql 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48766305/

相关文章:

Mysql 排序使用两列

Laravel 5.4 和 Vue.js 2.0 发出值而不是 Error 实例

php - 从不同页面上的 PHP 表单更改 HTML 元素类 - 自定义 CMS

Mysql 未安装 - 尝试将其与 RoR 一起使用

php - 如何在'sudo apt-get install lampp-server ^之后获得phpmyadmin

php - 使用范围内的价格过滤产品

php - 在 laravel 中将 union 作为数据库表

php - 如何在 Laravel 7 中的数组索引中返回字符串

php - 如何从 PHP 函数返回 2 个查询的组合结果?

php - ftp_connect fatal error : call undefined function