PDO Update batch Function batch update database operation using GOModel

Description

GOModel update function provides a simplest way to update the batch 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 updateBatch($dbTableName, $updateBatchData, $where = array());
                                

Parameters Details

Details Type Example
$dbTableName - Table name to update records string Any table name like "orderTable", "wp_posts" etc
$updateData - Array of Associative array of records to be updateed, with columnName as key and columnValue as value assoc. array array("orderNumber" => "78", "customerName" => "BKG", "address" => "140 shakti nagar"), array("orderNumber" => "99", "customerName" => "BKG", "address" => "140 shakti nagar")
$where - where condition array assoc. array array(array("orderId", 7), array("orderId", 8))

Examples

  
                                $GOModel = new GOModel(); //create object of the GOModel class
                                $GOModel->connect("localhost", "root", "", "database");//connect to database
                                /* Update function */
                                $updateBatchData = array(array("orderNumber" => "78", "customerName" => "BKG", "address" => "140 shakti nagar"), array("orderNumber" => "99", "customerName" => "BKG", "address" => "140 shakti nagar"));
                                $where = array(array("orderId", 7), array("orderId", 8));
                                $GOModel->updateBatch("orderTable", $updateBatchData, $where);
                            

More Examples

 
                                //Example 1
                                $updateBatchData = array(array("orderNumber" => "78", "customerName" => "BKG", "address" => "140 shakti nagar"), array("orderNumber" => "99", "customerName" => "BKG", "address" => "140 shakti nagar"));
                                $where = array(array("orderId", 7), array("orderId", 8));
                                $GOModel->updateBatch("orderTable", $updateBatchData, $where);

                            

Result/Output

Record will be updated in database

Debug

Option Details Example
$GOModel->getLastQuery(); Return last query executed UPDATE `orderTable` SET `orderNumber`=?,`customerName`=?,`address`=? WHERE `orderId`= ?
print_r($GOModel->error) Print errors (if any)
$GOModel->rowsChanged; Return Rows changed 1