Skip to content

Commit

Permalink
edited the connect file to contain the information of the connection …
Browse files Browse the repository at this point in the history
…as environment variables -fixes #6
  • Loading branch information
mennamamdouh committed May 4, 2023
1 parent 7f1bed6 commit 5ba7d60
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions ecommerce-website/components/connect.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
<?php

$db_name = 'mysql:host=localhost;dbname=shop_db';
$user_name = 'root';
$user_password = '';
require_once __DIR__ . '/../vendor/autoload.php';

$conn = new PDO($db_name, $user_name, $user_password);
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();

$database_host = $_ENV['DATABASE_HOST'];
$database_port = $_ENV['DATABASE_PORT'];
$database_user = $_ENV['DATABASE_USER'];
$database_password = $_ENV['DATABASE_PASSWORD'];
$database_name = $_ENV['DATABASE_NAME'];

$dsn = "pgsql:host=$database_host;port=$database_port;dbname=$database_name";

$conn = new PDO($dsn, $database_user, $database_password);

?>

0 comments on commit 5ba7d60

Please sign in to comment.