sql – PHP How can I write this code into a function?

I would like some help on how can I write the code below inside a function.

This is the second file where I’m calling the function.

require "index.php";

$db = new con_db();
$conn = $db -> connection();
$runSQL = new table();

$sql = "insert into students (ID, Name, Gender, Age) values(1234, 'John', 
    'Male', 19)";
$results = $runSQL -> insert($sql, $conn);

This is the index.php file

function insertSQL($query, $conn){
try{
    $dp = $conn -> prepare($query);
    $dp -> execute();   
    $results = $dp -> fetchAll();
    $dp -> closeCursor();
    return $results;
    }
catch(PDOException $e)
    {   
        $error_out = new report_error();
        $error_out -> http_error("Internal Error:nn" . $e -> getMessage());
    }
}