Insert Update Delete using PHP and mysql for Frontaccounting – crud

Insert Update Delete using PHP and mysql for Frontaccounting – crud

In this Post We Will Explain About is Insert Update Delete using PHP and mysql for Frontaccounting – crud With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to how to insert update delete record using php and mysql with frontaccountingExample

In this post we will show you Best way to implement php mysql add edit delete same page using frontaccounting, hear for frontaccounting Select Insert Update Delete In Php MySQL Examplewith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Insert function :

function live_stock($custom_table_name, $data_res){
    $sql_query = "INSERT INTO ".TB_PREF.$custom_table_name."(";
    $sql_query = " VALUES (";
    foreach($data_res as $key=>$value){
        $sql_query .= $key.",";
		if(is_array($value)) { 
			if($value[1] == 'date')				
				$sql_query .=  db_escape(date2sql($value[0])).",";
			if($value[1] == 'float')
				$sql_query .= $value.",";
		}else 
			$sql_query .= db_escape($value).",";
    }
    $sql_query = substr($sql_query, 0, -1).")";
    $sql_query = substr($sql_query, 0, -1).")";
    db_query($sql_query.$sql_query, "Could not insert data_res to table {$custom_table_name}");
	return  db_insert_id();
}

Update Functions

function live_update($custom_table_name, $primary_key ,$data_res ){
    $sql_query = "UPDATE ".TB_PREF.$custom_table_name." SET ";
    foreach($data_res as $key=>$value){
		if(is_array($value)) { 
			if($value[1] == 'date')				
				$sql_query .= $key." = ". db_escape(date2sql($value[0])).",";
			if($value[1] == 'float')
				$sql_query .= $key." = ". $value.",";
		}else 
			$sql_query .= $key." = ".db_escape($value).",";
    }
    $sql_query = substr($sql_query, 0, -1);
    $sql_query .= " where ".$primary_key[0]." = ".$primary_key[1];
	return  db_query($sql_query, "Could not update data_res on table {$custom_table_name}");	 
}

Get function:

 
 function kv_get_all($custom_table_name, $li_wh_condition = null){
    $sql_query = "SELECT * FROM ".TB_PREF.$custom_table_name." WHERE 1=1";
    if($li_wh_condition != null) {
		foreach($li_wh_condition as $key=>$value){
			$sql_query .= " AND {$key} = ${value}";
		}
    }
    $data_result = db_query($sql_query, "Could not get data_res from {$custom_table_name}");
    $data_res = array();
    while($row = $data_result->fetch_assoc()) {
        $data_res[] = $row;
    }
    return $data_res;
}

GetRow of Data:function

 
 function kv_get_row($custom_table_name, $li_wh_condition = null){
    $sql_query = "SELECT * FROM ".TB_PREF.$custom_table_name." WHERE 1=1";
    if($li_wh_condition != null) {
		foreach($li_wh_condition as $key=>$value){
			$sql_query .= " AND {$key} = ${value}";
		}
    }
	$sql_query .= ' LIMIT 1'; 
    $data_result = db_query($sql_query, "Could not get data_res from {$custom_table_name}");
	$data_res = db_fetch($data_result);
    
    return $data_res;
}

Get Single Value:function

function kv_get_single_value($tablename, $column_single, $li_wh_condition=null){
	$sql_query = "SELECT ".$column_single." FROM ".TB_PREF.$tablename." WHERE 1=1";
    foreach($li_wh_condition as $key=>$value){
        $sql_query .= " AND {$key} = ${value}";
    }
    return db_get_single_value($sql_query, "Could not get data_res from {$tablename}");
}

Get With two or more Joining Tables :

function kv_get_results_join($main_table, $joins, $columns=array(), $li_wh_condition=null){
    $sql_query = "SELECT ";
    if(count($columns)>0){
        foreach ($columns as $value) {
            $sql_query .= $value.",";
        }
        $sql_query = substr($sql_query, 0, -1);
    }else{
        $sql_query .= " *";
    }
    $sql_query .= " FROM ".TB_PREF."{$main_table} ";
    foreach ($joins as $value) {
        if(isset($value['join'])){
            $sql_query .= " {$value['join']} JOIN ".TB_PREF.$value['custom_table_name'].' ON '.$value['li_wh_condition'];
        }else{
            $sql_query .= " INNER JOIN ".TB_PREF.$value['custom_table_name'].' ON '.$value['li_wh_condition'];
        }
    }
    $sql_query .= " WHERE 1=1 ";
    foreach($li_wh_condition as $key=>$value){
        $sql_query .= " AND {$key} = ${value}";
    }
    //echo $sql_query;
    $data_result = db_query($sql_query, "Could not get data_res!");
    $data_res = array();
    while($row = $data_result->fetch_assoc()) {
        $data_res[] = $row;
    }
    return $data_res;
}

delete function

function kv_delete($custom_table_name, $li_wh_condition){
    $sql_query = "DELETE FROM ".TB_PREF.$custom_table_name." WHERE 1=1";
    foreach ($li_wh_condition as $key=>$value) {
        $sql_query .= " AND ".$key."=".$value;
    }
    $data_result = db_query($sql_query, "Could not your delete data_res from {$custom_table_name}");
    return $data_result;
}

Example

I hope you have Got What is Frontaccounting common class for Insert, Update, Delete, Get SQL Functions And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.

Leave a Comment