What are the advantages and disadvantages of using PHP to handle text files instead of a database like MySQL?

When handling text files in PHP instead of using a database like MySQL, some advantages include simplicity, portability, and ease of implementation for small-scale projects. However, text files may not be as efficient for large datasets, lack advanced querying capabilities, and can be prone to data corruption if not managed properly.

// Example of reading a text file in PHP
$filename = 'data.txt';
$file = fopen($filename, 'r');

if ($file) {
    while (($line = fgets($file)) !== false) {
        echo $line;
    }
    fclose($file);
} else {
    echo 'Error opening file.';
}