Executes an update statement with minimal SQL markup and is called from the objSQL class.
See also: Batch Update Operations
mixed obj_update ( [str table, [array data[, str where ]]] )
Result resource/object or false on failure.
<?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
The obj_update method with the obj_batch_data helper method allows you to easily perform batch update operations.
<?php
try
{
$trans = $dbh->obj_transaction();
//array key must be a unique field in a row (ie: primary key, part #, mfg product #, etc. )
//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
}
?>
See also: obj_batch_data