What are the potential pitfalls of not limiting data retrieval from a database when using PHP for web development?

Not limiting data retrieval from a database in PHP can lead to performance issues, security vulnerabilities, and potential data breaches. To prevent this, it's important to implement proper data retrieval limits in your queries to ensure only the necessary data is fetched from the database.

// Limiting data retrieval from a database in PHP
$limit = 10; // Set the limit to 10 records
$query = "SELECT * FROM table_name LIMIT $limit";
$result = mysqli_query($connection, $query);

// Fetch and display the data
while ($row = mysqli_fetch_assoc($result)) {
    // Display data here
}