簡體   English   中英

laravel 看不到我的本地主機數據庫錯誤:SQLSTATE [3D000]:目錄名稱無效:1046 未選擇數據庫

[英]laravel not seeing my localhost database error : SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected

我有一個問題,我的 Laravel 沒有檢測到我的本地主機 phpmyadmin 數據庫,我的配置設置為本地主機,我已經嘗試將 ip 更改為 127.0.0.1,我現在有點堅持這個。

數據庫配置:

'fetch' => PDO::FETCH_CLASS,

/*
|--------------------------------------------------------------------------
| 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' => env('DB_CONNECTION', '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' => [

    

    'mysql' => [
        'driver'    => 'mysql',
        'host'      => env('127.0.0.1'),
        'database'  => env('credito'),
        'username'  => env('root'),
        'password'  => env(''),
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
        'strict'    => false,
    ],

   
],

數據庫.php

'mysql' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'strict' => false,
        'engine' => null,
    ],

.env更新 .env 中的值才是正確的方法。

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

另一個問題可能是 Laravel 沒有檢測到您的應用程序環境。 您可以檢查它正在使用的環境

command line: php artisan env

Just make sure that you have the same credentials 
        'host' => env('127.0.0.1'),
        'database'  => env('credito'),
        'username'  => env('root'),
        'password'  => env(''),on your config/database.php and .env file, restart your apache server

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM