App\services\Database::insert PHP Method

insert() public method

public insert ( $data, $table = null )
    public function insert($data, $table = null)
    {
        $keys = "";
        $values = "";
        $table = $table ?: $this->tableName;
        foreach ($data as $key => $value) {
            if ($value == end($data)) {
                $keys .= '`' . $key . '`';
                $values .= '"' . $value . '"';
            } else {
                $keys .= '`' . $key . '`,';
                $values .= '"' . $value . '", ';
            }
        }
        $sql = "INSERT INTO {$table} ({$keys}) VALUES ({$values})";
        return $this->query($sql);
    }