• 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 run or debug php on Visual Studio Code (VSCode)

Ajax GET request fails in laravel 8

How to run a shell as root from php (apache)

Is it possible to change the table name in the migration file-laravel

Merge key and value of array index [duplicate]

cakephp save drag and drop list order to database

how to redirect the user back to desired URL after login page in PHP?

No result using makeStyles Material UI in react 18

Reading input in php from terminal

Update Order custom Field value with WooCommerce REST API

How to execute sql code based on fetch array

How to change the app environment at run time?

Losing session data after POST from third party website

Google API Heatmap Layer exception, why?

Wordpress 'post_type_link' hides permalink

About Contact Privacy policy Terms and conditions