Overview

Packages

  • objSQL

Documentation

  • objSQL Connection
  • objSQL Error Handling
  • General Queries
  • Prepared Statements
  • Transactions
  • Resultset Methods
  • Helper Method - Select Query
  • Helper Method - Update Query
  • Helper Method - Insert Query
  • Helper Method - Delete Query
  • Helper Method - Paging Query
  • Helper Method - Row Count Query
  • Utility Methods

Classes

  • cubrid_connection
  • cubrid_prepare
  • cubrid_resultset
  • cubrid_statement
  • cubrid_transaction
  • mysql_connection
  • mysql_prepare
  • mysql_resultset
  • mysql_statement
  • mysql_transaction
  • obj_access
  • objSQL
  • pdo_connection
  • pdo_prepare
  • pdo_resultset
  • pdo_statement
  • pdo_transaction
  • pgsql_connection
  • pgsql_prepare
  • pgsql_resultset
  • pgsql_statement
  • pgsql_transaction
  • sqlite3_connection
  • sqlite3_prepare
  • sqlite3_resultset
  • sqlite3_statement
  • sqlite3_transaction
  • sqlsrv_connection
  • sqlsrv_prepare
  • sqlsrv_resultset
  • sqlsrv_statement
  • sqlsrv_transaction
  • Overview
  • Package
  • Class
  • Tree
 

objSQL Resultset Methods

Associative Resultsets

The obj_fetch_assoc() method returns a resultset as an associative array.

Returns: Array or null if no more rows

The obj_field() method returns the resultset record for the named column and is case-sensitive.

Returns: Mixed

See also: Numeric Resultsets | Object Resultsets | Result/Resultset Statement Methods

<?php

try
{
    
$rs = $dbh->obj_select( "mytable", "color,size,price", "product='balloons'", "price" );
    
    if ( 
$dbh->obj_error() )
        throw new 
Exception( $dbh->obj_error_message() );
        
    while ( 
$rs->obj_fetch_assoc() ) 
    {
        
printf ( "%s %s %s \n", $rs->obj_field( "color" ), 
                                
$rs->obj_field( "size" ), 
                                
$rs->obj_field( "price" );
    }
    
    echo 
$rs->obj_num_rows();
    
    
$rs->obj_free_result();
}
catch ( 
Exception $e ) 
{
    
//log error and/or redirect user to error page
} 

?>

Numeric Resultsets

The obj_fetch_num() method returns a resultset as a numeric array.

Returns: Array or null if no more rows

The obj_field() method returns the resultset record for the numeric column.

Returns: Mixed

<?php

try
{
    
$rs = $dbh->obj_select( "mytable", "color,size,price", "product='balloons'", "price" );
    
    if ( 
$dbh->obj_error() )
        throw new 
Exception( $dbh->obj_error_message() );
        
    while ( 
$rs->obj_fetch_num() ) 
    {
        
printf ( "%s %s %s \n", $rs->obj_field( 0 ), 
                                
$rs->obj_field( 1 ), 
                                
$rs->obj_field( 2 );
    }
    
    echo 
$rs->obj_num_rows();
    
    
$rs->obj_free_result();
}
catch ( 
Exception $e ) 
{
    
//log error and/or redirect user to error page
} 

?>

Back to top

Object Resultsets

The obj_fetch_object() method returns a resultset as an object. The fields ( column names ) are case-sensitive.

Returns: Object or null if no more rows

<?php

try
{
    
$rs = $dbh->obj_select( "mytable", "color,size,price", "product='balloons'", "price" );
    
    if ( 
$dbh->obj_error() )
        throw new 
Exception( $dbh->obj_error_message() );
        
    while ( 
$obj = $rs->obj_fetch_object() ) 
    {
        
printf ( "%s %s %s \n", $obj->color, 
                                
$obj->size, 
                                
$obj->price );
    }
    
    echo 
$rs->obj_num_rows();
    
    
$rs->obj_free_result();
}
catch ( 
Exception $e ) 
{
    
//log error and/or redirect user to error page
} 

?>

Back to top

Result/Resultset Statement Methods

The obj_num_rows() method returns the number of rows from a select statement. The SQLite3 driver does not have a native PHP num rows method and uses a simulated num rows query, but it is very inefficient and can time out even on small recordsets. Both the SQLite3 and SQLSRV PDO drivers return -1 from the rowCount() method. The obj_row_count() helper method is recommended for all situations requiring an accurate and efficient num rows count.

Returns: Unsigned integer or -1 on failure

The obj_num_fields() method returns the number of fields from a select statement.

Returns: Unsigned integer or -1 on failure

The obj_affected_rows() method returns the number of affected rows from an insert/update/delete statement.

Returns: Unsigned integer or -1 on failure

The obj_free_result() method frees the statement and resultset resources from a select statement.

Returns: True or False on failure

<?php

try
{
    
$rs = $dbh->obj_select( "mytable", "color,size,price", "product='balloons'", "price" );
    
    if ( 
$dbh->obj_error() )
        throw new 
Exception( $dbh->obj_error_message() );
        
    echo 
$rs->obj_num_rows();
    echo 
$rs->obj_num_fields();
    
    
$rs->obj_free_result();
    
    
$rs = $dbh->obj_update( "mytable", array( "color" => "blue" ), "id=6" );
    
    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
} 

?>

Back to top

objSQL 3.2.0 API documentation generated by ApiGen 2.8.0

Documentation licensed under a Creative Commons Attribution 3.0 Unported License.