What role does the primary key (PK) play in modifying individual rows in a MySQL table using PHP?

When modifying individual rows in a MySQL table using PHP, the primary key (PK) is crucial in identifying the specific row that needs to be updated. By specifying the primary key value in the SQL query, you can target the exact row you want to modify without affecting other rows in the table.

<?php
// Connect to MySQL database
$mysqli = new mysqli("localhost", "username", "password", "database");

// Define the primary key value
$primary_key = 1;

// Define the new values to update
$new_value = "New Value";

// Prepare SQL query to update the row with the specified primary key
$query = "UPDATE table_name SET column_name = '$new_value' WHERE primary_key_column = $primary_key";

// Execute the query
$mysqli->query($query);

// Close database connection
$mysqli->close();
?>