What are some best practices for replacing placeholders with column values in PHP without hardcoding column types?

When replacing placeholders with column values in PHP without hardcoding column types, it is best practice to dynamically fetch the column names from the database and use them to replace the placeholders. This ensures that your code remains flexible and can adapt to changes in the database structure without manual adjustments.

// Assume $row is an associative array containing column names as keys and their respective values
// Assume $query is a SQL query string with placeholders for column names

// Get column names from the array
$columns = array_keys($row);

// Replace placeholders with column names
foreach ($columns as $column) {
    $query = str_replace(":$column", $row[$column], $query);
}

// Now $query contains the SQL query with placeholders replaced by column values