Create table from array with prepare

I tried this in local, and I think you have multiple fields inside $fields so I’ve added them in array.

Just look at the code below; it works fine as tested:

add_action('your_hook', 'createTableFromFields');
function createTableFromFields($tablename)
{
    $wpdb = $this->db;
    $tablename = $wpdb->prefix . $tablename;
    $fields = array('PersonID','LastName');
    $sql="CREATE TABLE IF NOT EXISTS %s (id INT(6) UNSIGNED
        AUTO_INCREMENT PRIMARY KEY";
    $test = array();
    foreach ($fields as $field) {
        $test[] =  $field." TEXT";
    }
    $t = implode(",", $test);
    $sql .= ",%s)";

    $result = $wpdb->query($wpdb->prepare(sprintf($sql, $tablename, $t)));
    return $result;
}