Project Pages

PHP Classes
SourceForge
Downloads
Archived Documentation

DB Connection Methods

objSQL
obj_close

Error Handling Methods

obj_error
obj_error_message

Statement Methods

obj_delete
obj_insert
obj_paging
obj_query
obj_select
obj_update

Statement Argument Methods

obj_batch_data
obj_cols
obj_data
obj_limit
obj_offset
obj_order_by
obj_sort_order
obj_table
obj_where

Resultset Methods

obj_affected_rows
obj_fetch_assoc
obj_fetch_num
obj_fetch_object
obj_field
obj_free_result
obj_num_fields
obj_num_rows

Prepared Statement Methods

obj_bind
obj_close_statement
obj_execute
obj_free_statement
obj_prepare_statement

Transaction Methods

obj_commit
obj_rollback
obj_savepoint
obj_transaction

Utility Methods

obj_escape
obj_info
obj_row_count


obj_batch_data()

Description:

Sets the data, id and col arguments for a batch delete or update statement and is called directly from the objSQL class.

  • The data and id arguments are required.
  • The optional col argument is required for batch updates.
  • The data argument MUST be a key value pair array with the table column as the key for batch updates.
  • The data argument can be a comma delimited string or an array for batch deletes.
  • It is highly recommended to perform batch operations within a Transaction block.

Parameters:

void obj_batch_data ( mixed data, str id[, str col ] )


Batch Update Example:

<?php      

try     
{     
    
$trans $dbh->obj_transaction();    
      
    
//array key must be a unique field in a row (ie: primary key, part #, mfg product #, etc. )  
    //array values are the data to update
    //the second argument is the column name for the unique field  
    //the third argument is the column to update  
    
$dbh->obj_batch_data( array( 12345S => 12.00,  
                                 
12345M => 12.50,  
                                 
12345L => 12.50,  
                                 
12345XL => 13.00,  
                                 
12345XXL => 13.00 ), "stock_id""price" );    
      
    
$dbh->obj_table"products" );    
         
    
$rs $dbh->obj_update();     
         
    if ( 
$dbh->obj_error() )     
    {     
        
$trans->obj_rollback();     
             
        throw new 
Exception$dbh->obj_error_message() );     
    }   

    
$trans->obj_commit();    
             
    echo 
$rs->obj_affected_rows();     
         
}     
catch ( 
Exception $e )      
{     
    
//log error and/or redirect user to error page     
}      

?>   


Batch Delete Example:

<?php     

try    
{    
    
$trans $dbh->obj_transaction();   
     
    
//data argument can be an array or comma delimited string 
    //value(s) should be a unique field in a row (ie: primary key, part #, mfg product #, etc. )  
    
$data = array( 1234,2345,3456,4567,5678,6789 ); 
    
$data "1234,2345,3456,4567,5678,6789"
     
    
//the second argument is the column name for the unique field 
    
$dbh->obj_batch_data$data"employee_id" );   
     
    
$dbh->obj_table"employees" );   
            
    
$rs $dbh->obj_delete();    
        
    if ( 
$dbh->obj_error() )    
    {    
        
$trans->obj_rollback();    
            
        throw new 
Exception$dbh->obj_error_message() );    
    }  

    
$trans->obj_commit();   
            
    echo 
$rs->obj_affected_rows();    
        
}    
catch ( 
Exception $e )     
{    
    
//log error and/or redirect user to error page    
}     

?>