What are the potential security risks of storing sensitive data in a plaintext file accessible to anyone on a PHP-based website?

Storing sensitive data in a plaintext file accessible to anyone on a PHP-based website poses a significant security risk as the data can be easily accessed and exploited by malicious users. To mitigate this risk, sensitive data should be stored securely, such as in a database with proper encryption and access control mechanisms in place.

// Example of securely storing sensitive data in a PHP file
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}
?>