• 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

Laravel 8 Multiple Relationships for Factory

Adding the custom page with add_menu_page function on Wordpress

Timber: Single post pagination does not work (wp_link_pages)

SQL AVG() to 2 decimals

zsh: command not found: php

Transfer data between JavaScript and PHP through JSON

How do I get friend list from Friends table with counts of friends of my friends

Unable to match results of php hash_hmac() and coldfusion hmac()

virtctl works when executed via command line but not from php exec()

PHP Get value from JSON [duplicate]

Entity provider not working in security.yml php symfony3.4 ({"code":401,"message":"bad credentials"}.)

Fatal error: [] operator not supported for strings

Dropdown with current value from Mysql

Issue with laravel eloquent model property

Autoloading classes in PHPUnit using Composer and autoload.php

About Contact Privacy policy Terms and conditions