php-dotenv
php-dotenv copied to clipboard
problems using DotEnv
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.
You Can share your code here please ? You use autoload with composer ?
HI, No i am not using composer
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
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; }`
Maybe you could use composer
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';