Mysql laravel看不到我的本地主机数据库错误:SQLSTATE[3D000]:目录名称无效:1046未选择数据库
我有一个问题,我的Laravel没有检测到我的localhost phpmyadmin数据库我的配置设置为local host,我尝试将ip更改为127.0.0.1,我现在有点被卡住了 数据库配置:Mysql laravel看不到我的本地主机数据库错误:SQLSTATE[3D000]:目录名称无效:1046未选择数据库,mysql,database,laravel,model-view-controller,Mysql,Database,Laravel,Model View Controller,我有一个问题,我的Laravel没有检测到我的localhost phpmyadmin数据库我的配置设置为local host,我尝试将ip更改为127.0.0.1,我现在有点被卡住了 数据库配置: 'fetch' => PDO::FETCH_CLASS, /* |-------------------------------------------------------------------------- | Default Database Connection Name |--
'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,
],
],
Database.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没有检测到您的应用程序环境。
您可以检查它使用的环境
命令行:php artisan env
Database.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,
],
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
.env以正确的方式更新.env中的值
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
另一个问题可能是Laravel没有检测到您的应用程序环境。
您可以检查它使用的环境
命令行:php artisan env
为什么要编辑database.php您应该在哪里更改.env
此问题的任何更新?为什么要编辑database.php您应该在哪里更改.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