Unsupported driver [ ] in laravel - database

i am facing issue of unsupported driver while hitting my API i have following configurations in my config/database.php
'mysql' => [
'driver' => env('DB_CONNECTION'),
'host' => env('DB_HOST'),
'port' => env('DB_PORT'),
'database' => env('DB_DATABASE'),
'username' => env('DB_USERNAME'),
'password' => env('DB_PASSWORD'),
// 'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
and my env file
DB_CONNECTION=mysql
DB_HOST=someURLsomeUrl
DB_PORT=3306
DB_DATABASE=ovadahealth_dev
DB_USERNAME=ovadahealth_user
DB_PASSWORD=password
I have spent an hours in this issue and i cant find out where is the issue when i hit my api in postman it says:
{
"status": false,
"message": "Unsupported driver []"
}
Here your help will be highly appreciated!

use php artisan config:clear to clear your configuration.

Related

SMTP Time out error - Send email from localhost

I tried to send email using Google SMTP from localhost, but I keep getting the SMTP time out. error.
This is my config:
'EmailTransport' => [
'default' => [
'className' => 'Smtp',
// The following keys are used in SMTP transports
'host' => 'tls://smtp.gmail.com',
'port' => 587,
'username' => 'xxxxx#gmail.com',
'password' => 'xxxxxsecret',
'log' => true,
'tls' => true,
'domain' => 'localhost',
],
],
I'm running my app on Wampp server.
Please help me, thank you in advanced!
Using mailtrap, you can test this locally. If this works, then most likely the configuration is incorrect or the email isn't being sent through google mail.
https://mailtrap.io - create account and use for free.
'EmailTransport' => [
'default' => [
'className' => 'Smtp',
'host' => 'smtp.mailtrap.io',
'port' => 2525,
'timeout' => 30,
'username' => 'YOUR_USERNAME',
'password' => 'YOUR_PASSWORD',
'client' => null,
'tls' => true,
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
],
],
You can also change the port from 587 to 465 and check. Allow Google to trust your local email server.

How to use multiple db2 databases in Laravel

Currently i use the package cooperl/laravel-db2 for the database connection. For my project, i should to toggle schema database.
I try this in db2.php :
'connections' => [
'ibmi_1' => [
...
'host' => '***********',
'username' => '***********',
'password' => '***********',
'database' => 'database',
'prefix' => '',
'schema' => 'schema_1',
'port' => *****,
'date_format' => 'Y-m-d H:i:s',
...
],
'ibmi_2' => [
...
'host' => '***********',
'username' => '***********',
'password' => '***********',
'database' => 'database',
'prefix' => '',
'schema' => 'schema_2',
'port' => *****,
...
],
And this in .env
DB_CONNECTION=ibmi_1
DB_HOST=
DB_PORT=
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=
DB_CONNECTION=ibmi_2
DB_HOST=
DB_PORT=
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=
But when i try in tinker
DB::connection('ibmi_2')
I have this error
InvalidArgumentException with message 'Database connection [ibmi_2] not configured.'
What is wrong ?
The problem was that the database configuration wasn't in bootstrap/cache/config.php.

Sending email from gmail using CakePHP3, Connection refused

I am having a problem with configuration with CakePHP3 for sending email from my Gmail account. I always get an error Connection refused. I don't know where the problem is. So I hope anyone here has any knowledge about sending emails from my Gmail account.
EDIT: I am using GoDaddy hosting server
Here are my configurations.
'gmail' => [
'host' => '(ssl://)smtp.gmail.com',
'port' => 465,
'username' => 'MyGmail#gmail.com',
'password' => 'pass',
'className' => 'Smtp',
'tls' => true
],
'Email' => [
'gmail' => [
'transport' => 'gmail',
'from' => 'myGmail#gmail.com',
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
],
],
First update email config in CakePHP
Your Updated config/app.php file should be as :
'EmailTransport' => [
'default' => [
'className' => 'Smtp',
// The following keys are used in SMTP transports
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'timeout' => 30,
'username' => 'username#domain.com',
'password' => 'your_password',
],
],
and now use the mail function of CakePHP Email Function.

Undefined class constant 'SQLSRV_ENCODING_SYSTEM'

when trying to run php artisan migrate on laravel i'm getting the error
In database.php line 79:
Undefined class constant 'SQLSRV_ENCODING_SYSTEM'
i have the sql drivers etc installed but unsure how to solve this problem
database.php file
'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' => '',
'options' => [PDO::SQLSRV_ENCODING_SYSTEM => false], // Used for MSSQL encoding
],
Explanations:
PDO::SQLSRV_ENCODING_SYSTEM is PDO_SQLSRV Driver Constant, not an option name. You should use PDO::SQLSRV_ATTR_ENCODING => PDO::SQLSRV_ENCODING_SYSTEM in options. Have in mind, that this option is Microsoft Drivers for PHP for SQL Server specific driver attribute (one of PDO::SQLSRV_ATTR_ENCODING and PDO::SQLSRV_ATTR_DIRECT_QUERY).
<?php
...
'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' => '',
'options' => [PDO::SQLSRV_ATTR_ENCODING => PDO::SQLSRV_ENCODING_SYSTEM]
],
...
?>
Notes:
Documentation: Microsoft SQL Server Functions (PDO_SQLSRV) and Constants (Microsoft Drivers for PHP for SQL Server).

Laravel Unit Test separate database

Can somebody help me, how can i run my tests, but they will interact with database copy or a virtual database. I know, that i need to use phpunit.xml file, but how? Give me a example please.
I have found a workaround for this.
In your config/database.php bellow mysql add:
'mysql_testing' => [
'driver' => 'mysql',
'host' => env('TESTING_DB_HOST', 'localhost'),
'database' => env('TESTING_DB_DATABASE', 'forge'),
'username' => env('TESTING_DB_USERNAME', 'forge'),
'password' => env('TESTING_DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
And now in your .env add the values for:
TESTING_DB_HOST=localhost
TESTING_DB_DATABASE=homestead_testing
TESTING_DB_USERNAME=homestead
TESTING_DB_PASSWORD=secret
Now you can run
php artisan migrate —database=mysql_testing
And the last thing - open your phpunit.xml file in the app folder and add this:
<env name="DB_CONNECTION" value="mysql_testing"/>
<?php
return [
// other stuff
'default' => env('DB_DEFAULT', 'mysql'),
'connections' => [
'sqlite_testing' => [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
],
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
],
// other stuff
];
For controller
public function createApplication()
{
putenv('DB_DEFAULT=sqlite_testing');
$app = require __DIR__ . '/../../bootstrap/app.php';
$app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();
return $app;
}
public function setUp()
{
parent::setUp();
Artisan::call('migrate');
}
public function tearDown()
{
Artisan::call('migrate:reset');
parent::tearDown();
}
#pardeep in test\CreatesApplication trait there is just one function
add this putenv('DB_DEFAULT=sqlite_testing');

Resources