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
obj_transaction

Utility Methods

obj_escape
obj_info


obj_row_count

Description:

Returns the number of rows from a select count() query and is called from the objSQL class. This helper method is dependant on the named connection instance and can be called anywhere within a query block.

  • The table name argument is required.
  • The optional cols argument specifies which column(s) to count and is entered as a comma delimited string. Entering an empty value is equivilent to an asterisk (*).
  • The optional where argument allows you to limit which rows are selected and only requires the column and its value. You can use any of the normal operators used in SQL statements:
    • "color IN ('blue','red')"
    • "color='red' AND material='leather'"
    • "brand LIKE 's%'"
    • "price BETWEEN 200 AND 400"
  • Statement and resultset resources are released internally.

Parameters:

int obj_row_count ( str table[, str cols[, str where ]] )


Returns:

Unsigned integer or -1 on failure.


Example:

<?php  

try  
{  
    
$num_rows $dbh->obj_row_count"mytable""id""l_name='Jones'" );  
          
    if ( 
$dbh->obj_error() )  
        throw new 
Exception$dbh->obj_error_message() );  
      
    echo 
"<p>Your query returned $num_rows results</p>";  
     
}  
catch ( 
Exception $e )   
{  
    
//log error and/or redirect user to error page  
}   


try  
{  
    
//set arguments using statement argument helper methods   
    
$dbh->obj_table"mytable" );   
    
$dbh->obj_cols"id" );  
    
$dbh->obj_where"l_name='Jones'" );  
        
    
$num_rows $dbh->obj_row_count();  
          
    if ( 
$dbh->obj_error() )  
        throw new 
Exception$dbh->obj_error_message() );  
      
    echo 
"<p>Your query returned $num_rows results</p>";  
     
}  
catch ( 
Exception $e )   
{  
    
//log error and/or redirect user to error page  
}   

?>

See also: obj_affected_rows, obj_num_fields, obj_num_rows