• 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

Unable to Edit config.inc.php

How do I upload a laravel project on cPanel shared hosting?

Batch request Google Calendar php API

json_encode turns array into an object

Symfony redirect if already loggedin from login page

Not able to access model in the controller mautic

Wordpress add responsive srcset header image to theme

Insert And Retrieve Data in MySQL with $.post Noob Question

Can't remotely connect to MySQL error (13) with PHP script, connecting through CLI works

how to insert data into select2 search input after scan using qrcode

Add restriction to WooCommerce coupons by allowed user ID

Object of class stdClass could not be converted to string error

Last order would be re-order in wooCommerce. How is it possible?

MongoDB Duplicate Documents even after adding unique key

Prevent blank space in pdf pages (DomPdf)

About Contact Privacy policy Terms and conditions