Can anyone help me to fix this problem please
the error is database [postgres] not configured.
here is my .env file :
DB_CONNECTION=postgres
DB_HOST=localhost
DB_PORT=5432
DB_DATABASE=referentiel
DB_USERNAME=postgres
DB_PASSWORD=postgres
and here is my database.php:
'default' => 'postgres',
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '5432'),
'database' => 'referentiel',
'username' => env('postgres', ''),
'password' => env('postgres', ''),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
'sslmode' => 'prefer',
],
Change the default parameter in your config to match the name of your postgres connection - pgsql in your case:
'default' => 'pgsql',
And put correct database parameters in your .env file.
Try to edit your .env
From: DB_CONNECTION=postgres
To: DB_CONNECTION=pgsql
i think the problem in php.ini if you use xampp open app xampp > config > php.ini
find ;extension=php_pdo_pgsql.dll
;extension=php_pdo_sqlite.dll
delete ;
change extension=php_pdo_pgsql.dll
extension=php_pdo_sqlite.dll
Related
I'm really surprised the Laravel documentation is limited for explaining how to connect to MS SQL Server. There are two areas that I think need configuration -- the .env file and the database.php. Most examples on the web don't show the same format compared to Laravel 7. I would like to know where I can find the correct info for the following.
How to tell what port my DB is on
What to enter for URL
What to enter for HOST
When testing the connection it says 'driver not found' - is it saying the details are incorrect or is it looking for a missing file?
before changing the database.php file it has the word forge as the second argument for the env() function - what is forge???
If anyone can point me to a good resource id be in your debt!
DB_CONNECTION=sqlsrv
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=test_db_1
DB_USERNAME=sa
DB_PASSWORD=mypassword
```
and the database.php...
'default' => env('DB_CONNECTION', 'sqlsrv'), ...
...
'sqlsrv' => [
'driver' => 'sqlsrv',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'test_db_1'),
'username' => env('DB_USERNAME', 'sa'),
'password' => env('DB_PASSWORD', 'mypassword'),
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
],
Your DB_HOST will always be localhost, so if the database is on the same machine, 127.0.0.1 will be fine. TCP port 1433 is typically the port used by a default instance of SQL Server, set it to DB_PORT=1433.
Laravel Forge is a tool for deploying and configuring web applications and can be used to automate the deployment of any web application that uses a PHP server. Since we are using the .env to overwrite the values in config/database.php there is no need to worry about the "forge" values. Finally, you may need to install drivers on the machine to support PHP and SQL Server.
.env
DB_CONNECTION=sqlsrv
DB_HOST=127.0.0.1
DB_PORT=1433
DB_DATABASE=test_db_1
DB_USERNAME=sa
DB_PASSWORD=mypassword
config/database.php
'sqlsrv' => [
'driver' => 'sqlsrv',
'url' => env('DATABASE_URL'),
'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,
]
I have laravel 5.8 setup and working with MySQL. I need to connect a second database (SQL Server).
I have the following in my .env file
DB_EXT_CONNECTION=sqlsrv
DB_EXT_HOST=0.0.0.0
DB_EXT_PORT=1433
DB_EXT_DATABASE=database
DB_EXT_USERNAME=user
DB_EXT_PASSWORD=password
database.php
'sqlsrv' => [
'driver' => 'sqlsrv',
'url' => env(''),
'host' => env('DB_HOST', '0.0.0.0'),
'port' => env('DB_PORT', '1433'),
'database' => env('DB_DATABASE', 'database'),
'username' => env('DB_USERNAME', 'user'),
'password' => env('DB_PASSWORD', 'password'),
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
],
I am running xampp and have the following dll's installed
extension=php_pdo_sqlsrv_73_ts.dll
extension=php_sqlsrv_73_ts.dll
I keep getting
SQLSTATE[HY000]: [Microsoft][ODBC Driver 11 for SQL Server]Protocol error in TDS stream (SQL:select * from [dbo].[t_people]) (View: C:\xampp\htdocs
I have
$users = DB::connection('sqlsrv')->table('dbo.t_people')->select('*')->get();
in my blade template.
Change all the DB_DATABASE from your config file to DB_EXT_DATABASE, as you wrote in your .env file.
Try instead of
$users = DB::connection('sqlsrv')->table('dbo.t_people')->select('*')->get();
do the
$users = DB::connection('sqlsrv')->table('t_people')->select('*')->get();
And don't do it in your blade files, do it in controller.
I have a requirement to add SSL to the backend mysql database and connect using Laravel. But unable to know the way to do it.
Do I need to have MySql Db configured to use encrypted connection and then provide some parameters in Database.php file in Laravel.
My site has https enabled.
Please guide what should be taken care and to be done.
What you will need to is first configure SSL/TLS on your MySQL Server and the instructions will be specific to the OS hosting the MySQL Server as well as the MySQL Version itself.
Here's an example guide for MySQL 5.x and Ubuntu:
https://www.digitalocean.com/community/tutorials/how-to-configure-ssl-tls-for-mysql-on-ubuntu-16-04
Once you've done this, you can configure your laravel app to tell it how to communicate over encrypted mysql connection by adding this line to your db config:
'options' => array(
PDO::MYSQL_ATTR_SSL_CA => $cert_base . '/ssl-ca-bundle.pem'
),
the full config will look something like this in config/database.php
'mysql' => array(
'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' => true,
'engine' => null,
'options' => array(
PDO::MYSQL_ATTR_SSL_CA => '/path/to/ssl-ca-bundle.pem'
),
),
I would like to know: How can I maintain different credentials for my database. Like when I am working locally, laravel should rely on Database A while after pushing it on my server it should rely on Database B?
Do like this
config/database.php (production setting)
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'db'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', '********'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
.env file (local setting)
APP_ENV=local
APP_DEBUG=true
APP_URL=project.dev
DB_HOST=localhost
DB_DATABASE=mydb
DB_USERNAME=root
DB_PASSWORD=
I think the better approach is to use different variable names for local, staging and production something like below (not tested).
database.php
use Illuminate\Support\Facades\App;
//... Other code
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => (App::environment('local') ?
env('DB_HOST', '127.0.0.1') : App::environment('production')) ?
env('PROD_DB_HOST') : env('STAGING_DB_HOST'),
'port' => (App::environment('local') ?
env('DB_PORT', '3306') : App::environment('production')) ?
env('PROD_DB_PORT') : env('STAGING_DB_PORT'),
'database' => (App::environment('local') ?
env('DB_DATABASE', 'forge') : App::environment('production')) ?
env('PROD_DB_DATABASE') : env('STAGING_DB_DATABASE'),
'username' => (App::environment('local') ?
env('DB_USERNAME', 'root') : App::environment('production')) ?
env('PROD_DB_USERNAME') : env('STAGING_DB_USERNAME'),
'password' => (App::environment('local') ?
env('DB_PASSWORD', 'localhost') : App::environment('production')) ?
env('PROD_DB_PASSWORD') : env('STAGING_DB_PASSWORD'),
//... other variables
],
//... other code
.env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=localdb
DB_USERNAME=root
DB_PASSWORD=admin123
STAGING_DB_HOST=127.0.0.1
STAGING_DB_PORT=3306
STAGING_DB_DATABASE=stagdb
STAGING_DB_USERNAME=staginguser
STAGING_DB_PASSWORD=stag123
PROD_DB_HOST=127.0.0.1
PROD_DB_PORT=3306
PROD_DB_DATABASE=proddb
PROD_DB_USERNAME=produser
PROD_DB_PASSWORD=prod123
use env and change accordingly.
Config::set('database.default', 'production-DB');
Laravel Configs
When I trying to install drupal-7 in my server, at the setup database step it shows the error
Failed to connect to your database server. The server reports the following message: SQLSTATE[42000]: Syntax error or access violation: 1231 Variable 'sql_mode' can't be set to the value of 'NO_AUTO_CREATE_USER'.
The database name, username, and password are all correct.
Is there any solution to this problem?
How have I fixed (Syntax error or access violation: 1231 Variable 'sql_mode' can't be set to the value of 'NO_AUTO_CREATE_USER') problem in laravel
SO go to config/database.php
in mysql connection add the following
code
'modes' => [
'ONLY_FULL_GROUP_BY',
'STRICT_TRANS_TABLES',
'NO_ZERO_IN_DATE',
'NO_ZERO_DATE',
'ERROR_FOR_DIVISION_BY_ZERO',
'NO_ENGINE_SUBSTITUTION',
],
The whole connection will be something like the following
'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' => true,
'engine' => null,
'modes' => [
'ONLY_FULL_GROUP_BY',
'STRICT_TRANS_TABLES',
'NO_ZERO_IN_DATE',
'NO_ZERO_DATE',
'ERROR_FOR_DIVISION_BY_ZERO',
'NO_ENGINE_SUBSTITUTION',
],
],
Drupal isn't allowed to create a new user in your MySQL database. You need at least MySQL 5.0.15