• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

PHP DOTENV unable to load env vars

phpenvironment-variables


PHP Snippet 1:

require 'vendor/autoload.php';

$dotenv = new Dotenv\Dotenv(__DIR__);
$dotenv->load();

$DB_HOST = $_ENV['DB_HOST'];

PHP Snippet 2:

require 'vendor/autoload.php';

$dotenv = new Dotenv\Dotenv(__DIR__);
$dotenv->load();

$DB_HOST = getenv('DB_HOST');

PHP Snippet 3:

$dotenv = Dotenv\Dotenv::createUnsafeImmutable(__DIR__);
$dotenv->load();

$DB_HOST = getenv('DB_HOST');

Related Snippets

How to get rid of ampersand using WP Nonce URL and WP Redirect or PHP header

How to read laravel_session cookies saved in cookie memory of browser in client side?

How do I call a php file with axios?

Laravel Get Days In Month From Month Number?

Display the default discounted price and percentage on Woocommerce products

Symfony - "framework.test" config is not set to true

Creating command to backup MySql database in Laravel

MySQL default time format UTC or GMT?

(Cache::lock()) -> get() -- Under what conditions does it return false?

Laravel php artisan serve to mimic HTTPS

Remove categories with all childs derived from parent category

If action is on a different page do I use fwrite function

Why do I have invalid argument supply for foreach in Laravel for json response? [duplicate]

generate an Excel file using PHP

I want to display default profile image if user do not have profile image

About Contact Privacy policy Terms and conditions