mySimple PHP SQL Generator Function

Terkadang (sering sih) males banget nulis kode SQL jika sedang memrogram..harus insert into blablabla belum lagi ngebinding ke variabel varibel yang dibutuhkan…Tentu ini sangat merepotkan kalo bekerja dengan banyak form dan dikejar dedline …. :Diseng – iseng karena melihat kemampuan PHP yang banyak memanfaatkan Array , tidak ada salahnya menulis fungsi yang mungkin dapat membantu semua :<?php /*** generate sql for easy to SQL** @param String $mode add,del,edit* @param String $table table name* @param Array $data contain the data that will include in operation* @param String $where where condition* @return String*/public static function generate_sql($mode,$table,$data=array(),$where=”1=1″){$sql = “”;switch($mode){case “add” :$sql = “INSERT INTO $table”;$akey = array();$avalue = array();foreach ($data as $key => $value) {$akey[] = $key;$avalue[] = “‘”.$value.”‘”;}$skey = implode(“,”,$akey);$svalue = implode(“,”,$avalue);$sql .= “(“.$skey.”) values(“.$svalue.”)”;break;case “del” :$sql = “DELETE FROM $table WHERE $where”;break;case “edit” :$sql = “UPDATE $table SET”;$aupdate = array();foreach ($data as $key => $value) {$aupdate[] = “$key=’$value'”;}$supdate = implode(“,”,$aupdate);$sql .= ” $supdate WHERE $where”;break;}return $sql;} ?> intinya function ini dapat bekerja dalam 3 mode => add, edit, dan delete…ah males ah jelasinnya tak beri contoh aja deh…untuk add :<?php ……. $data = array(‘user_info_id’=>$userid,’user_id’=>$this->ms,’address_type’=>’ST’,’address_type_name’=>’mobilestockiestclient’,’first_name’=>$name,’address_1’=>$address,’country’=>$country,’state’=>$state,’city’=>$city);$sql = ps_multiorder::generate_sql(“add”,”#__vm_user_info”,$data);  …….?> untuk edit :<?php ………….$userid = $user_info_id;        $data = array(‘address_1’=>$address,’country’=>$country,’state’=>$state,’city’=>$city);$where = “user_info_id=’$userid'”;$sql = ps_multiorder::generate_sql(“edit”,”#__vm_user_info”,$data,$where);………….?> dan untuk delete :<?php………$userid = $user_info_id;        $data = array();$where = “user_info_id=’$userid'”;$sql = ps_multiorder::generate_sql(“del”,”#__vm_user_info”,$data,$where);………….?>yah sekian deh postingannya daripada kosong…kalo ada ide saran jangan sungkan – sungkan menghubungi saya di radityo_pw[at]is[dot]its[dot]ac[dot]id