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

Statement Argument Methods

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_update

Description:

Executes an update statement with minimal SQL markup and is called from the objSQL class.

  • The table name and data arguments are required unless using statement argument methods.
  • The data argument MUST be a key value pair array with the table column as the key.
  • The optional where argument allows you to limit which rows are updated and only requires the column and its value. You can use any of the normal operators used in SQL statements:
    • "location IN ('Athens','London')"
    • "location='Valdosta' AND dept='IT'"
    • "salary BETWEEN 20000 AND 40000"
  • obj_update will update all records in a database table if used without a where clause and steps should be taken in any script or program to utilize a confirmation before executing this method.

Parameters:

mixed obj_update ( [str table, [array data[, str where ]]] )


Returns:

Result resource/object or false on failure.


Example:

<?php 

try 

    
$data = array( "color" => "blue"
                   
"type"  => "leather"
                   
"price" => 36.95 ); 
     
    
$rs $dbh->obj_update"products"$data"prod_id=21" ); 
     
    if ( 
$dbh->obj_error() ) 
        throw new 
Exception$dbh->obj_error_message() ); 
         
    echo 
$rs->obj_affected_rows(); 
     

catch ( 
Exception $e )  

    
//log error and/or redirect user to error page 
}  


try 

    
//set arguments using statement argument helper methods  
    
$dbh->obj_table"products" );   
    
$dbh->obj_data( array( "color" => "blue""type" => "leather""price" => 36.95 ) ); 
    
$dbh->obj_where"prod_id=21" );                
     
    
$rs $dbh->obj_update(); 
     
    if ( 
$dbh->obj_error() ) 
        throw new 
Exception$dbh->obj_error_message() ); 
         
    echo 
$rs->obj_affected_rows(); 
     

catch ( 
Exception $e )  

    
//log error and/or redirect user to error page 
}  

?>      

See also: obj_delete, obj_insert, obj_paging, obj_query, obj_select