Mysql Insert Operation

Description

Insert new records in a table using associative array. Instead of writing long insert queries, you needs to pass array of keys(columns) and values(insert values). This function will automatically create query for you and inserts data.

Function Reference :
          		void dbInsert(string $table_name, assoc. array $insert_array); 
            

Parameters

Name Type Required Parameter Info Example
table_name string Yes The name of the table to insert new records any table name like employee_table,user_table
insert_array associative array Yes Associative array with key as column name and values as column value. array("username"=>"abcd","gender"=>"male","age"=>29)

Examples

            <?php 
            $sdb= new SimplifiedDB();
            $sdb->dbConnect("localhost","username","password","dbuser"); 
            $sdb->dbInsert("user_roles",array("role_name"=>"Contributer","role_description"=>"Contribues for the system")); 
            ?> 
        

Result

New row will be inserted in table.

Debuging

Debug Operation Result/Output
$sdb->query INSERT INTO `user_roles`(`role_name`,`role_description`) VALUES ('Contributer','Contribues for the system')
$sdb->last_insert_id 32
$sdb->rows_affected 1
$sdb->message_info Connected to database
$sdb->error_info

More Examples

 
            $insertRoles=array();
            $insertRoles["role_name"]="Manager";
            $insertRoles["role_description"]="Manages system";
            $sdb->dbInsert("user_roles",$insertRoles);