为CRUD构建自定义函数

New to the concept of php custom function and was wondering how to build a custom function for INSERT

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql = "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('John', 'Doe', 'john@example.com')";

if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?> 

Can anyone help. Will appreciate if I can have link to a tutorial as well.

Here is a helpful tutorial for a begginer with Php. Hope this help: http://alejoferguson.blogspot.com/2014/08/tutorial-php-mysql-recomendado_27.html

I would not recommend you to have server and password information on the same page your doing the query but rather to have it separately as is explained in this simple tutorial. ALso it provides you with the source code at the end of the tutorial.

Guide yourself by the images in this tutorial.