<?php
/**
 * Created by PhpStorm.
 * User: sunusi
 * Date: 2019-01-22
 * Time: 07:54
 */


function queryInsert($table, $data)
{

    //variable declaration
    $columns = "";
    $valueset = "";
    $values = "";

    //loop
    foreach ($data as $column => $value) {
        $columns = $columns . ', `' . $column . '`';
        $valueset = $valueset . ', \'' . $value . '\'';
        $values = $values . ',' . $value;
    }

    //trimming the first comma from the result above
    $columns = ltrim($columns, ',');
    $valueset = ltrim($valueset, ',');
    $values = ltrim($values, ',');

    //statement
    $sql = "INSERT INTO ${table} ( ${columns} ) VALUES ( ${valueset} )";

    return $sql;
}