What are the benefits and drawbacks of using PHP to save data to a text file instead of a database?
When saving data to a text file instead of a database using PHP, some benefits include simplicity, speed, and ease of implementation for small-scale projects. However, drawbacks may include limited querying capabilities, potential data loss if the file is not properly managed, and security risks if sensitive information is stored in plain text.
<?php
// Data to be saved to a text file
$data = "Hello, World!";
// Open the file in write mode
$file = fopen("data.txt", "w");
// Write the data to the file
fwrite($file, $data);
// Close the file
fclose($file);
?>
Related questions
-
PHP file handling file_exists
-
session timeout PHP security risks
-
Composer dependencies PHP version