I'm working with laravel on Manjaro and I installed php and Mariadb.
in my laravel project when it wants to connect to database it show me "Illuminate\Database\QueryException
could not find driver (SQL: select * from users where email = sample.co#example.com limit 1) ";
database config:
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'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'),
]) : [],
],
My env file:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=farsifor_m
DB_USERNAME=root
DB_PASSWORD=mypassword
I replaced php8 by php 7.4 . It solved the issue.
Related
I have the following problem, when I configure my database in the .env file and carry out the migrations, I see that they are carried out but in a different DB than the one I have configured, and the truth is that I do not know why, I attach images.
mi archivo .env, apunta mi base de datos prueba2:
enter image description here
but the migration is done to my other database bdperformlead:
enter image description here
check some configuration
config > database.php
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'read' => [
'host' => [
env('SLAVE_DB_HOST', '127.0.0.1'),
],
'port' => env('SLAVE_DB_PORT', '3306'),
'database' => env('SLAVE_DB_DATABASE', 'forge'),
'username' => env('SLAVE_DB_USERNAME', 'forge'),
'password' => env('SLAVE_DB_PASSWORD', ''),
],
'write' => [
'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' => 'utf8',
'collation' => 'utf8_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'),
]) : [],
],
if database name get using .env, check .env properly and run
php artisan optimize:clear
I change the configuration to connect database MySQL server workbench, I have entered host, username, and password in .env but I have error SQLSTATE[HY000] [1045] Access denied for user.
But I have entered in config/database.php connection success.
My .env file contains:
DB_CONNECTION=mysql
DB_HOST=0.0.0.0
DB_PORT=3306
DB_DATABASE=xxxx
DB_USERNAME=xxxx
DB_PASSWORD=xxxxxx
My config/database.php is :
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', 'localhost'),
'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' => false,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
in dabase.php I delete env and entered connection to this code connection success
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', 'localhost'),
'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' => false,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
in dabase.php I delete env and entered connection to this code connection success
I have tried db connection by add pem cert files and pdo_mysql setup. But always getting below error.
SQLSTATE[HY000] [2002] Connection refused
Laravel config/database.php configured like below.
'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' => '',
'sslmode' => env('DB_SSLMODE', 'prefer'),
'options' => array(
PDO::MYSQL_ATTR_SSL_CA => 'certs/ca-cert.pem',
PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => false
),
'strict' => true,
'engine' => null,
],
I try to make 2 connections to a database in laravel. I always get:
error database [] not configured.
Pls help me master.
This is my controller:
class DashboardController extends Controller
{
public function index(request $request)
{
$tes = DB::connection('mysql2')->select('SELECT * from hari');
// $tes = tes::find(1);
dd($tes);
}
---env--
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=crud55
DB_USERNAME=root
DB_PASSWORD=
DB_DATABASE_2=db_susantokun
DB_USERNAME_2=root
DB_PASSWORD_2=
------------database.php
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'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'),
]) : [],
],
'mysql2' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE_2', 'db_susantokun'),
'username' => env('DB_USERNAME_2', 'root'),
'password' => env('DB_PASSWORD_2', ''),
'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'),
]) : [],
],
This error occurs when calling http://localhost:8000/dashboard
this is InvalidArgumentException
Database [mysql2] not configured.
how to fix it?
You may have to rebuild the configuration cache. Run the following command in your laravel root directory:
php artisan config:cache
after chnage .env file you should restart php artisan serve service
I deployed my project to an AWS EC2 instance using Elastic Beanstalk. I used this tutorial https://www.youtube.com/watch?v=ISVaMijczKc as a reference while deploying. I am following everything as it is in the tutorial but I ended up with an error.
Database hosts array is empty. (SQL: select * from
resource_categories)
The following are my codes.
database.php
<?php
define('RDS_HOSTNAME', $_SERVER['RED_HOSTNAME']);
define('RDS_USERNAME', $_SERVER['RED_USERNAME']);
define('RDS_PASSWORD', $_SERVER['RED_PASSWORD']);
define('RDS_DB_NAME', $_SERVER['RED_DB_NAME']);
return [
'default' => env('DB_CONNECTION', 'mysql'),
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
],
'mysql' => [
'driver' => 'mysql',
'host' => RDS_HOSTNAME,
'port' => env('DB_PORT', '3306'),
'database' => RDS_DB_NAME,
'username' => RDS_USERNAME,
'password' => RDS_PASSWORD,
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => false,
'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),
],
],
];
.ENV
APP_NAME="MyProject"
APP_ENV=development
APP_KEY=base64:FlVBd61BUEzVx6ACa6OOn3Jrp4z+VRpug+F1K1ZeJOs=
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=myDB
DB_USERNAME=root
DB_PASSWORD=
I've gone through a similar problem and MarkB helped me. There's a specific procedure you must follow when you SSH into the instance.
If you run
export
you can see that there's no variable named RDS_HOSTNAME in that Linux shell and that's why you're getting that error.
If you run
/opt/elasticbeanstalk/bin/get-config environment
you can see an object with the list of properties, including that RDS_HOSTNAME.
If you run
/opt/elasticbeanstalk/bin/get-config environment -k RDS_USERNAME
you get the value associated with that particular property. This value needs to be saved in a variable and exported so that other commands can recognize it.
If you run
export RDS_USERNAME="value"
then when you run
export
you can see that this is now available.
Now if you run the command you wanted it's likely gonna work (you might need to repeat this for RDS_USERNAME, RDS_PASSWORD and RDS_DB_NAME).
Note: if that didn't work, then your problem might be similar to this one.
This is a bug report which might be related to this problem. The long and the short is that if the ConnectionFactory gets passed a NULL value it will (erroneously) trigger that error. I suspect that all of your RDS variables are empty.
To set these values, you can follow instructions here.