What are best practices for storing individual values from an SQL query in variables for further use in PHP?

When storing individual values from an SQL query in variables for further use in PHP, it is best practice to use prepared statements to prevent SQL injection attacks. After executing the query, fetch the result as an associative array and then assign the values to variables for easier access and manipulation in your PHP code.

// Assume $conn is the database connection object

// Prepare the SQL query
$stmt = $conn->prepare("SELECT column1, column2 FROM table WHERE condition = ?");
$stmt->bind_param("s", $condition);

// Execute the query
$stmt->execute();

// Store the result in variables
$stmt->bind_result($value1, $value2);
$stmt->fetch();

// Now $value1 and $value2 contain the individual values from the query