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_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

Utility Methods

obj_escape
obj_info
obj_row_count


obj_transaction

Description:

Initiates a transaction and disables autocommit.

Transactions are a means to ensure a database's integrity when one or more queries fail. Queries are usually grouped together in logical blocks and are committed or rolled back when certain conditions are met. In general, any statement that alters a database record such as insert, delete and update is considered a transactional statement. Statements such as create database, create table, drop database, etc. should be executed outside of a transaction block.

  • If you are using the Firebird database server with multiple transactions, it is recommended to have the Firebird PDO extension enabled. This eliminates the deadlock issues with the standard interbase extension when updating the same table.
  • It is extremely important to explicitly commit or rollback a transaction block. Failure to do so may have unintended consequences such as a proceeding non-transactional query enabling autocommit and commiting queries in failed transaction blocks.

Parameters:

mixed obj_transaction ( void )


Returns:

Transaction instance or false on failure.


Example:

<?php

try
{
    
$trans $dbh->obj_transaction();
    
    
$data = array( "color" => "blue",
                   
"type"  => "leather",
                   
"price" => 36.95 );
                   
    
$rs $dbh->obj_update"products"$data"prod_id=21" );
    
    if ( 
$dbh->obj_error() )
        
$trans->obj_rollback();
        
    
$trans->obj_commit();    

}
catch ( 
Exception $e 
{
    
//log error and/or redirect user to error page
}

?>

See also: obj_commit, obj_rollback, obj_savepoint