View Single Post
Old 11-16-2008, 08:28 PM   #4 (permalink)
Enfernikus
The Addict
 
Enfernikus's Avatar
 
Join Date: Jun 2008
Posts: 335
Thanks: 2
Enfernikus is on a distinguished road
Default

The MYSQL_ASSOC constant in PHP is really just an integer that equates to one, a good chunk of that code you've written there could be greatly reduced with the use of a ternary operator. Unless I'm horribly mistaken ( I could be, I haven't tested this ) this should work.

PHP Code:
<?php

function loadFetch$assoc false$sql null )
{

    unset( 
$this->query_fetch );
    empty( 
$this->query_fetch );

    
$sql = ( is_null($sql) && isset($this->query_result) ) ? $this->query_result $sql;
    
$fetchType = ( $assoc ) ? 0;

    if ( !empty(
$sql) )
    {
        while ( 
$fetch mysql_fetch_array($sql$fetchType) )
        {
            
$this->query_result[] = $fetch;
        }

        if ( !
is_array($this->query_fetch) )
        {
            throw new 
Exception"An error occured while fetching the array" mysql_error() );
        } else {
            return 
$this;
        }
    }

}

?>
Enfernikus is offline  
Reply With Quote
The Following 2 Users Say Thank You to Enfernikus For This Useful Post:
codefreek (11-16-2008), Tanax (11-16-2008)