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_update

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_select

Description:

Executes a select statement with minimal SQL markup and is called from the objSQL class.

  • The table name argument is required. Supplying only this argument will return all rows from the named table.
  • The optional cols argument specifies which columns to return and is entered as a comma delimited string. Entering an empty value is equivilent to an asterisk (*).
  • The optional where argument allows you to filter your query 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'"
    • "location LIKE 's%'"
    • "salary BETWEEN 20000 AND 40000"
  • The optional order by argument is used to sort the resultset and only requires the column name.
  • The optional sort order argument is used to sort the order by argument in descending (desc) or ascending (asc) order.

Parameters:

mixed obj_select ( str table[, str cols[, str where[, str order by[, str sort order ]]]] )


Returns:

Result resource/object or false on failure.


Example:

<?php

try
{
    
//Return all rows from table
    
$rs $dbh->obj_select"mytable" );
    
    if ( 
$dbh->obj_error() )
        throw new 
Exception$dbh->obj_error_message() );
        
    echo 
$rs->obj_num_rows();
    
    
$rs->obj_free_result();
}
catch ( 
Exception $e 
{
    
//log error and/or redirect user to error page



try
{
    
//Return selected cols from table with filter
    
$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 );
    }
    
    
$rs->obj_free_result();
}
catch ( 
Exception $e 
{
    
//log error and/or redirect user to error page


?>


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