• 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

Additional price based on cart item count in WooCommerce

oauth-private.key does not exist or is not readable

Convert date and time to Jalali in Laravel

Undefined variable in Laravel 8 project (php 7.4)

Is there a way to correctly use sanitize_text_field and wp_unslash that doesn't cause psalm to error with "expects string, possibly different type"

Not able to override collapsible.js in magento 2

Getting public posts of a random user from Facebook API

How to create a video stream from a single dynamic image in PHP

Laravel Command Schedule Not Working Properly

Render the content of default_filter.php in Joomla front-end

Populate Dynamic Dropdowns List in Codeigniter

PHP returning an error message and false

Exception thrown during the rendering of a template("Parameter "id" for route "url" must match "[^/]++" ("" given) to generate a corresponding URL.")

How to change 'users' auth table and use another instead Laravel

Transpose csv file data [duplicate]

About Contact Privacy policy Terms and conditions