Make an encrypted Mysql database connection

Asked

Viewed 120 times

-1

To make a connection to the Mysql database use this code in PHP:

$host = "host";
$usuario = "usuario";
$banco = "banco";
$senha = "senha";
$pdo = new PDO('mysql:host='.$host.';dbname='.$banco, $usuario, $senha);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

Is there any way to encrypt the password and login? Because the client found this file unsafe with the access data so loose in FTP....

1 answer

0

The most common is to use environment variables to store database connection credentials.

The file pattern is widely used .env (dotenv or "dot env") to write environment variables. And to read these variables into the code you can use a library like the josegonzalez/php-dotenv.

For this to be safe it is important that the file .env stay out of the internet accessible folder (generally public_html or www).

Another alternative is to configure environment variables directly on the server, but requires some knowledge in server administration. And then read the values using the function getenv.

Browser other questions tagged

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