11-16-2008, 08:28 PM
|
#4 (permalink)
|
|
The Addict
Join Date: Jun 2008
Posts: 335
Thanks: 2
|
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 ) ? 1 : 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; } }
}
?>
|
|
|
|