What are the advantages of storing data in a MySQL table for handling large datasets in PHP applications?

Storing data in a MySQL table for handling large datasets in PHP applications offers advantages such as efficient data retrieval using SQL queries, scalability to handle increasing amounts of data, built-in indexing for faster search operations, and data integrity through constraints and relationships.

// Connect to MySQL database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

$conn = new mysqli($servername, $username, $password, $dbname);

// Retrieve data from MySQL table
$sql = "SELECT * FROM table_name";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // Output data of each row
    while($row = $result->fetch_assoc()) {
        echo "ID: " . $row["id"]. " - Name: " . $row["name"]. "<br>";
    }
} else {
    echo "0 results";
}

// Close MySQL connection
$conn->close();