PDO Insert Function insert database operation using GOModel


GOModel insert function provides a simplest way to insert the data into database by passing the data in form of associative array. You need to pass table name and array of data to insert function and rest will be managed by the script.

Function Defination

                                void function insert($dbTableName, $insertData);

Parameters Details

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


                                $GOModel = new GOModel(); //create object of the GOModel class
                                $GOModel->connect("localhost", "root", "", "database");//connect to database
                                /* Insert function */
                                $GOModel->insert("order", array("orderNumber"=>1001, "customerName"=>"John Cena", "address"=>"140 B South Jercy");

More Examples

                                //Example 1
                                $insertData = array("orderNumber"=>1001, "customerName"=>"John Cena", "address"=>"140 B South Jercy");
                                $GOModel->insert("order", $insertData);

                                //Example 2
                                $insertEmpData["firstName"] = "Simon"; 
                                $insertEmpData["lastName"] = "jason";
                                $GOModel->insert("emp", $insertEmpData);


Record will be inserted in database


Option Details Example
$GOModel->getLastQuery(); Return last query executed INSERT INTO `emp` (`firstName`,`lastName`,`age`,`gender`,`status`) VALUES (?,?,?,?,?)
print_r($GOModel->error) Print errors (if any)
$GOModel->lastInsertId Return last insert Id 53
$GOModel->rowsChanged; Return Rows created/changed 1