What are the potential pitfalls of storing data in a .txt file as a database in PHP?

Storing data in a .txt file as a database in PHP can lead to potential pitfalls such as lack of data integrity, limited scalability, and slower performance compared to using a proper database management system like MySQL. To solve these issues, consider using a database system like MySQL or SQLite for better data management, scalability, and performance.

// Example of connecting to a MySQL database instead of using a .txt file
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database_name";

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

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