代码之家  ›  专栏  ›  技术社区  ›  ProgLover

连接mysql时出现Laravel问题

  •  0
  • ProgLover  · 技术社区  · 7 年前

    我正在尝试使用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
    

    对于这样的问题,大多数回复都是为了增加执行时间,但就我而言,我只是尝试简单的插入查询。我认为错误是连接失败,无法访问查询。。。

    这是我的数据库。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服务器。

    2 回复  |  直到 7 年前
        1
  •  0
  •   brombeer    7 年前

    在中进行更改(设置数据库端口) .env config/database.php .

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

        2
  •  0
  •   Adam Kozlowski    7 年前
    1. 您的脚本执行时间超过60秒,因此终止。

    2. 中有一个值 php.ini 定义PHP脚本可以运行的最长时间。

    3. 只需更新值(称为 max_execution_time )