How to update database data through Object Oriented Programming?
Share
How to update database data through Object Oriented Programming?
The first thing you can learn HTML, whether you want to become a professional web developer or just want to learn more about how websites work. The basic language for developing web pages and web applications is HTML. A server ...
Asynchronous Javascript One of AJAX’s benefits is it provides instantaneous feedback to the user because it requests information asynchronously from the backend web server. However, using AJAX does not guarantee the user will not wait for the asynchronous JavaScript and ...
How To Make Cookie Free Domain An HTTP cookie (also known as a web cookie, Internet cookie, browser cookie, or simply cookie) is a small piece of data sent from a website and stored on the user’s computer by the ...
If you want to update data using classes,
just create a class, then create a function inside the class
You can use the code like the following …
<php;
class updateClass
{
public $tblName;
function updateTable($tblName, $arr, $where)
{
$values = ’’;
$whereval = ’’;
foreach($arr as $key=>$val)
{
$values .= " `$key`= ’$val’,";
}
foreach($where as $key1=>$val1)
{
$whereval .= " `$key1`= ’$val1’ and ";
}
$values = rtrim($values,",");
$whereval = rtrim($whereval,"and ");
echo $qry = "Update $tblName SET ".$values." WHERE ".$whereval;
//mysql_query($qry);
}
}
$obj = new updateClass();
$arrFields = array("fname"=>"Rahul", "lastname"=>"Devgan");
$where = array("id"=>1,"cust_id"=>2);
$obj->updateTable("newtable", $arrFields, $where);
You have to create files and folders according to MVC structure and then from views you will request to the controllers and controller will send the request to Model, where your queries will be written and data will be updated.