What is the purpose of using OUT parameters in a MySQL procedure in PHP?

When using OUT parameters in a MySQL procedure in PHP, the purpose is to retrieve values from the procedure that are set within the procedure and return them back to the PHP script. This allows for the passing of data from the procedure to the PHP script, which can then be used for further processing or display.

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

// Prepare a MySQL procedure with OUT parameters
$query = "CALL get_user_info(?, ?, @username, @email)";
$stmt = $mysqli->prepare($query);

// Bind input parameters
$username = "john_doe";
$email = "john_doe@example.com";
$stmt->bind_param("ss", $username, $email);

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

// Retrieve OUT parameters
$stmt->close();
$result = $mysqli->query("SELECT @username AS username, @email AS email");
$row = $result->fetch_assoc();

// Display the retrieved values
echo "Username: " . $row['username'] . "<br>";
echo "Email: " . $row['email'];

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