Is it possible to evaluate variables stored in a database and use them as PHP variables in an efficient way?

When evaluating variables stored in a database and using them as PHP variables, it is important to ensure that the data is properly sanitized to prevent any security vulnerabilities such as SQL injection. One efficient way to do this is to fetch the data from the database, sanitize it using functions like mysqli_real_escape_string or prepared statements, and then assign it to PHP variables for further processing.

// Fetch data from the database
$query = "SELECT * FROM table_name WHERE condition";
$result = mysqli_query($connection, $query);

// Check if data is fetched successfully
if($result){
    // Fetch and sanitize data
    $row = mysqli_fetch_assoc($result);
    $variable1 = mysqli_real_escape_string($connection, $row['column1']);
    $variable2 = mysqli_real_escape_string($connection, $row['column2']);

    // Now you can use $variable1 and $variable2 as PHP variables
}