What are the advantages and disadvantages of using a text file versus a database for storing stock prices in PHP?

When deciding between using a text file or a database for storing stock prices in PHP, the main advantage of using a text file is simplicity and ease of implementation. Text files are lightweight and easy to read and write to, making them suitable for small-scale applications. However, databases offer better performance, scalability, and data organization, making them more suitable for larger applications with complex data requirements.

// Using a text file to store stock prices
$filename = 'stock_prices.txt';

// Writing data to the text file
$data = "AAPL 150.25\nGOOGL 2500.75\nAMZN 3200.50";
file_put_contents($filename, $data);

// Reading data from the text file
$stocks = file_get_contents($filename);
echo $stocks;