Ega
Ega

Reputation: 1

(LARAVEL) SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected

(LARAVEL) SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected I am trying to make a login page for my site, but when i tried to use the login feature, its give me error saying that no database is selected. i created the database using migration and user.php from laravel itself.

theres for all the code i think will have connection with the error, im sorry im still figuring out how this insert code works so i use Gdrive for that.

//config/database.php

        'mysql' => [
            'driver' => 'mysql',
            'url' => env('http://localhost/phpmyadmin/db_structure.php?server=1&db=tugasakhir'),
            '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' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ],

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE= tugasakhir
DB_USERNAME=root
DB_PASSWORD=

Upvotes: 0

Views: 1457

Answers (1)

Tithira
Tithira

Reputation: 662

In your database.php file do not have your own values, instead have the values in your .env file.

database.php

 'mysql' => [
            'driver' => 'mysql',
            'url' => env('DATABASE_URL'), //keep it like this
            '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' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ],

In your .env file you had a space in-front of your database name, remove it.

//from
DB_DATABASE= tugasakhir 
//to 
DB_DATABASE=tugasakhir

Upvotes: 1

Related Questions