How can the use of LIMIT in a SQL query help control the number of results displayed in a PHP script?

Using the LIMIT clause in a SQL query allows us to control the number of results returned from the database. By specifying a LIMIT value in our query, we can ensure that only a certain number of rows are fetched, which can help optimize performance and prevent overwhelming our PHP script with a large amount of data to process.

<?php
// Establish a connection to the database
$pdo = new PDO('mysql:host=localhost;dbname=database_name', 'username', 'password');

// Prepare and execute a SQL query with a LIMIT clause to retrieve only 10 rows
$stmt = $pdo->prepare("SELECT * FROM table_name LIMIT 10");
$stmt->execute();

// Fetch and display the results
while ($row = $stmt->fetch()) {
    echo $row['column_name'] . "<br>";
}
?>