php-dotenv icon indicating copy to clipboard operation
php-dotenv copied to clipboard

problems using DotEnv

Open ftalamo opened this issue 3 years ago • 6 comments

Hi, I am using the php-dotenv and whe i call it in other php file i get " Uncaught Error: Class 'DevCoder\DotEnv' not found in /var/www/html..." the file exists the path is right, in fact the use statement work with not error.

ftalamo avatar Dec 22 '21 20:12 ftalamo

You Can share your code here please ? You use autoload with composer ?

phpdevcommunity avatar Dec 22 '21 20:12 phpdevcommunity

HI, No i am not using composer

ftalamo avatar Dec 22 '21 20:12 ftalamo

you need to import the file into your before to use . exemple : <?php require 'src/DotEnv.php'; but I strongly advise you to use autoload

phpdevcommunity avatar Dec 22 '21 21:12 phpdevcommunity

I did it, but get the same error..

`<?php require '/DotEnv.php';

function OpenCon() {
(new DotEnv(DIR . '/connection.env'))->load(); $dbhost = getenv(dbhost); $dbuser = getenv(dbuser); $dbpass = getenv(dbhpass); $db = getenv(db); $conn = new mysqli($dbhost, $dbuser, $dbpass,$db) or die("Connect failed: %s\n". $conn -> error);

return $conn; }`

ftalamo avatar Dec 23 '21 11:12 ftalamo

Maybe you could use composer

ZbyRih avatar Jan 27 '22 12:01 ZbyRih

You need to import DotEnv.php in your main file and all php files inside Processor folder in DotEnv.php file. As a reminder to import DotEnv.php if you have it in the src folder you need to import it like this: require 'src/DotEnv.php';

dieg0varela avatar Mar 17 '22 14:03 dieg0varela