• 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

zsh: command not found: php

how to display a view on laravel 8 and not have a 404 NOT FOUND page?

How can I format this number correctly using PHP?

PHP: set a (deep) array key from an array [closed]

PHPExcel file download using AJAX call

Laravel dosen't connect with Oracle

Why rand() every time I refresh the page?

Vimeo API: how to save a vimeo into a subfolder?

Don't show recurring price for WooCommerce subscriptions worth 0$

PHP cURL (SSL certificate problem: self signed certificate in certificate chain)

Unsure why I am getting: Number of variables doesn't match number of parameters in prepared statement

correct PHP headers for pdf file download

How to fix " Uncaught TypeError: Argument 1 passed to JpGraphException::defaultHandler() " problem in php 7.1.3 and jpgraph 4.2.6?

CodeIgniter force_download is not working

How to remove index.php and index from the URL using htaccess | PHP

About Contact Privacy policy Terms and conditions