Access denied to bank with file . env

Asked

Viewed 23 times

0

Hi, I created a file. env to store my connection variables, when I take the values of these variables on a page without connection appears all the values but when I try to access the database, access denied. The credentials are right when I connect in the bank with them directly in the code (without the .env) works normal. Can anyone tell me where the mistake is?

Arquivo.env: I tried to put ip on the host and put no quotes

 BANCO_HOST="localhost"
BANCO_NOME="orcamento01"
BANCO_USUARIO="root"
BANCO_SENHA= ""

The connection:

  try {
            $conn = new PDO( 'mysql:host=' . getenv('BANCO_HOST') . ';dbname=' .  getenv('BANCO_NOME'),
            getenv('BANCO_USUARIO'),
            getenv('BANCO_SENHA') );

            $conn->exec("set names utf8");
            return $conn;
        } catch (\PDOException $erro) {
            echo $erro->getMessage();
        } 

The mistake:

SQLSTATE[HY000] [1045] Access denied for user ''@'localhost' (using password: NO)

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.