PDO Update Function update database operation using GOModel

Description

GOModel update function provides a simplest way to update the data into database by passing the data in form of associative array. You need to pass table name and array of data to update function and where condition data. Please note that you must set where condition to update specific data else all data will be updated.

Function Defination

  
                                void function update($dbTableName, $updateData);
                                

Parameters Details

Details Type Example
$dbTableName - Table name to update records string Any table name like "orderTable", "wp_posts" etc
$updateData - Associative array of records to be updateed, with columnName as key and columnValue as value assoc. array array("orderNumber"=>1001, "customerName"=>"John Cena", "address"=>"140 B South Jercy")

Examples

  
                                $GOModel = new GOModel(); //create object of the GOModel class
                                $GOModel->connect("localhost", "root", "", "database");//connect to database
                                /* Update function */
                                $GOModel->where("orderId", 7);//setting where condition
                                $GOModel->update("order", array("orderNumber"=>"44", "customerName"=>"BKG", "address"=>"140 shakti nagar"));
                            

More Examples

 
                                //Example 1
                                $updateData = array("orderNumber"=>1001, "customerName"=>"John Cena", "address"=>"140 B South Jercy");
                                $GOModel->where("orderId", 7);
                                $GOModel->update("order", $updateData);

                                //Example 2
                                $updateEmpData["firstName"] = "Simon"; 
                                $updateEmpData["lastName"] = "jason";
                                $GOModel->where("empId", 40);
                                $GOModel->update("emp", $updateEmpData);
                                
                            

Result/Output

Record will be updated in database

Debug

Option Details Example
$GOModel->getLastQuery(); Return last query executed UPDATE `emp` SET `firstName`=?,`lastName`=?,`age`=?,`gender`=?,`status`=? WHERE `empId`= ?
print_r($GOModel->error) Print errors (if any)
$GOModel->rowsChanged; Return Rows created/changed 1