Create Function SQL Query With Unlimited Columns and Value in PHP

9/23/2016 07:15:00 AM
Create Function SQL Query With Unlimited Columns and Value in PHP

Let's do It, I create something awesome to help your project with native PHP , i create this function cause me not learn framework but i think can applicated a Framework function in native PHP, that a code of function.

<?php 
function unlimited_insert($tabel,$kolom,$value)
{
    $total_kolom = count($kolom);
    $total_value = count($value);
 
 $query = "INSERT INTO ".$tabel;
 $query .= " (";
 for($counter_kolom = 0;$counter_kolom <= $total_kolom-1;$counter_kolom++)
 {
  $query .=$kolom[$counter_kolom];
        if($counter_kolom != count($kolom)-1)
        {
            $query .=",";
        }
 }
 $query .= ")";
    if($total_value != 0)
    {
        $query .= " VALUES (";
    }else{
        $query .= " VALUE (";
    }
    for($counter_value = 0;$counter_value <= $total_value-1;$counter_value++)
 {
        
  $query .=$value[$counter_value];
        if($counter_value != count($value)-1)
        {
            $query .=",";
        }
 }
    $query .=")";
    return $query;
}

$array_kolom = array("si","a","b");
$array_value = array("su","su","jablay");
echo unlimited("Table",$array_kolom,$array_value);
?>

Usage Of This Function :

unlimited(table,array_your_columns,array_your_value);

Benefit usage this function, you can add mysqli_escape_real_string, without manual setting in all your query, and you no need add many function for diferent query, this code can use for INSERT, DELETE,UPDATE simply CRUD query with 3 function in your library. 


IP Kamu Adalah :

Share this

Tidak ada hal yang spesial, cuman Blogger yang hanya sebatas tau tentang dunia Programer

Related Posts

Previous
Next Post »