Driver [app.database] not supported. Laravel 5.1 - laravel

Driver [app.database] not supported. Laravel 5.1
I have cloned a repository of a project of the company, and when trying to lift the project I throw myself the following error, already reviewed the connection parameters and all this well,
The error is with W7 and Laravel 5.1.
config.databases.php
return [
'fetch' => PDO::FETCH_CLASS,
'default' => env('DB_CONNECTION', 'mysql'),
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => storage_path('database.sqlite'),
'prefix' => '',
],
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => '4242',
'database' => env('DB_DATABASE', '***'),
'username' => env('DB_USERNAME', '***'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'options' => [
\PDO::ATTR_EMULATE_PREPARES => true
]
],
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
],
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
],
],
'migrations' => 'migrations',
'redis' => [
'cluster' => false,
'default' => [
'host' => '127.0.0.1',
'port' => 6379,
'database' => 0,
],
],
];

Related

Laravel configuration of "database.php" file not works

i want to connect to database using database.php file, but it's not works.
I do not have the .env file.
I have to configure something more, beyond the file database.php
file database.php:
<?php
return [
'default' => env('DB_CONNECTION', 'mysql'),
'connections' => [
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'my_database'),
'username' => env('DB_USERNAME', 'mydatabase'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
],
]
]
Some of you database connection values are set to take from env file. Since you are not using env, you have to set them in the database.php file manually.
return [
'default' => env('DB_CONNECTION', 'mysql'),
'connections' => [
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL', 'Enter your db url here'), <--
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'Your db name'), <--
'username' => env('DB_USERNAME', 'Db user name'), <--
'password' => env('DB_PASSWORD', 'Db password'), <--
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
],
]
]
Note: You might need to change these settings again for deployment. And you have serve it after changing the file.

Import databases infos from mysql in database.php [duplicate]

This question already has answers here:
Laravel: connect to databases dynamically
(8 answers)
Closed 3 years ago.
I would like to get databases informations stored in my database and add it in the database.php.
I tried to get all infos in the database but I always have an error like this :
[2019-04-18 20:22:20] laravel.ERROR: Call to a member function
connection() on null {"exception":"[object]
(Symfony\Component\Debug\Exception\FatalThrowableError(code: 0):
Call to a member function connection() on null at
/var/www/vhosts/xxxx.net/httpdocs/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1249)
I added this on the top of database.php :
<?php
use App\Campaign;
$database_infos = Campaign::all();
$campains_db = array();
foreach ($database_infos as $info) {
if (isset($info->db_name)) {
$campains_db[$info->keyword] = array(
'driver' => 'mysql',
'host' => $info->db_host,
'database' => $info->db_name,
'username' => $info->db_user,
'password' => decrypt($info->db_password),
'prefix' => $info->db_prefix,
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'strict' => false,
'engine' => null,
);
}
}
return [
'default' => env('DB_CONNECTION', 'mysql'),
'connections' => [
$campains_db,
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
],
'wordpress' => [
'driver' => 'mysql',
'host' => 'localhost',
'database' => '',
'username' => '',
'password' => '',
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
'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' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
'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' => '',
'prefix_indexes' => true,
'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' => '',
'prefix_indexes' => true,
],
],
'migrations' => 'migrations',
'redis' => [
'client' => env('REDIS_CLIENT', 'predis'),
'options' => [
'cluster' => env('REDIS_CLUSTER', 'predis'),
],
'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_DB', 0),
],
'cache' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_CACHE_DB', 1),
],
],
];
I found this on an other post :
The simplest solution is to set your database config at runtime.
Laravel might expect these settings to be loaded from the
config/database.php file, but that doesn't mean you can't set or
change them later on.
The config loaded from config/database.php is stored as database in
Laravel config. Meaning, the connections array inside
config/database.php is stored at database.connections.
Config::set("database.connections.mysql", [
"host" => "...",
"database" => "...",
"username" => "...",
"password" => "..."
]);

How to use multiple database in Lumen

We've using Lumen for building API's , Now we need to access multiple databases.
Currently using .env for database config but unable to found the way to multiple databases in .env
where we need to read 2nd connection ...
First, you'll need to configure your connections. If you don't already have one you'll need to create a config directory in your project and add the file config/database.php. It might look like this:
<?php
return [
'default' => 'accounts',
'connections' => [
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST'),
'port' => env('DB_PORT'),
'database' => env('DB_DATABASE'),
'username' => env('DB_USERNAME'),
'password' => env('DB_PASSWORD'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
'mysql2' => [
'driver' => 'mysql',
'host' => env('DB2_HOST'),
'port' => env('DB_PORT'),
'database' => env('DB2_DATABASE'),
'username' => env('DB2_USERNAME'),
'password' => env('DB2_PASSWORD'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
],
];
Once you've added your connection configurations, you can access them by getting the database manager object out of the container and calling ->connection('connection_name').
// Use default connection
app('db')->connection()->select('xx');
DB::connection()->select('yy');
// Use mysql2 connection
app('db')->connection('mysql2')->select('xx');
DB::connection('mysql2')->select('yy');
Hope this helps you!!
This also worked. In the current version of Lumen 5.7
config/database.php
<?php
return [
'default' => env('DB_CONNECTION', 'sqlsrv'),
'migrations' => 'migrations',
'connections' => [
'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' => '',
'prefix_indexes' => true,
],
'sqlsrv2' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '1433'),
'database' => env('DB_DATABASE2', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
],
],
];
.env
DB_CONNECTION=sqlsrv
DB_HOST=localhost
DB_PORT=1433
DB_DATABASE=database1
DB_USERNAME=username
DB_PASSWORD=password
DB_DATABASE2=database2
Usage:
Model: protected $connection = 'sqlsrv2';
Other: ->connection('sqlsrv2')
I hope i help you!
Reference:https://fideloper.com/laravel-multiple-database-connections

Troubleshouting laravel migrations for new database

I am trying to set a separate database for tests. For some reason when I run the migrations I have always a message saying: "Nothing to migrate."
Here is how I run the migrations:
php artisan migrate --database=mysql_test
Nothing to migrate.
And here is my config/database.php:
'default' => env('DB_CONNECTION', 'mysql'),
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
],
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'mydb'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'dev'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
'mysql_test' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'mydbtest'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'dev'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
And obviously I can login to the database mydbtest with the credentials in the config.
Updating here after some troubleshooting:
After emptying mydb database and running the same command it filled the mydb database not mydbtest. This means it does not take into account what I am giving as database connection name.
Any suggestions to troubleshoot this are welcome.
Thanks
I found the problem.
After commenting out this line in my .env file it works now:
#DB_DATABASE=mydb
Thanks

No connection could be made because the target machine actively refused it error in laravel 5

Subline database.conf file:
'default' => env('DB_CONNECTION', 'mysql'),
'connections' => [ 'sqlite' =>
[ 'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '', ],
'mysql' => [ 'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost').('homstead'==gethostname()?null:':33060'),
'port' => env('DB_PORT', 'localhost:3306'),
'database' => env('DB_DATABASE', 'homstead'),
'username' => env('DB_USERNAME', 'homstead'),
'password' => env('DB_PASSWORD', 'secret'),
'charset' => 'utf8', 'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null, ],
command prompt error:
Not sure why you are having multiple ports in the connection, you only need to have it under the port key
'default' => env('DB_CONNECTION', 'mysql'),
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => ''
],
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'homstead'),
'username' => env('DB_USERNAME', 'homstead'),
'password' => env('DB_PASSWORD', 'secret'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
]
Also removed the concatenated host string

Resources