This is just typical Cookie usage.
In DataBase.php,
session_start();
$_SESSION[‘username’] = 'Hasselhoff';
Then to use the 'username' cookie, in any other php file
just run session_start() again and that will be available there.
In OtherFile.php,
session_start();
echo $_SESSION[‘username’];
Edit: Using this in a sql query:
$userSelected = $_SESSION[‘username’];
$sql = mysqli_query($conn, "SELECT product_id, price FROM products WHERE username = '$userSelected'");
$results= $sql ->fetch_assoc();
This is basic attempt which is open to vulnerability.
Do read on prevention of sql injection here to make your code safer and
protected from php sql injection:
How can I prevent SQL injection in PHP?