Return to Snippet

Revision: 1222
at September 26, 2006 07:39 by gdonald


Updated Code
function sqlFetchArray( $query, $type='MYSQL_ASSOC' )
{
  if( in_array( 'mysql', $GLOBALS[ 'loaded_extensions' ] ) )
  {
    switch( $type )
    {
      case 'MYSQL_NUM':
        return @mysql_fetch_array( $query, MYSQL_NUM );
        break;
      case 'MYSQL_ASSOC':
        return @mysql_fetch_array( $query, MYSQL_ASSOC );
        break;
      case 'MYSQL_BOTH':
        return @mysql_fetch_array( $query, MYSQL_BOTH );
        break;
    }
  }
  elseif( in_array( 'mysqli', $GLOBALS[ 'loaded_extensions' ] ) )
  {
    switch( $type )
    {
      case 'MYSQL_NUM':
        return @mysqli_fetch_array( $query, MYSQLI_NUM );
        break;    
      case 'MYSQL_ASSOC':
        return @mysqli_fetch_array( $query, MYSQLI_ASSOC );
        break;    
      case 'MYSQL_BOTH':
        return @mysqli_fetch_array( $query, MYSQLI_BOTH );
        break;
    }
  }
}

Revision: 1221
at September 26, 2006 07:36 by gdonald


Initial Code
function sqlFetchArray( $query, $type='MYSQL_ASSOC' )
{
    if( in_array( 'mysql', $GLOBALS[ 'loaded_extensions' ] ) )
    {
        switch( $type )
        {
            case 'MYSQL_NUM':
                return @mysql_fetch_array( $query, MYSQL_NUM );
                break;
            
            case 'MYSQL_ASSOC':
                return @mysql_fetch_array( $query, MYSQL_ASSOC );
                break;
            
            case 'MYSQL_BOTH':
                return @mysql_fetch_array( $query, MYSQL_BOTH );
                break;
        }
    }
    elseif( in_array( 'mysqli', $GLOBALS[ 'loaded_extensions' ] ) )
    {
        switch( $type )
        {
            case 'MYSQL_NUM':
                return @mysqli_fetch_array( $query, MYSQLI_NUM );
                break;
            
            case 'MYSQL_ASSOC':
                return @mysqli_fetch_array( $query, MYSQLI_ASSOC );
                break;
            
            case 'MYSQL_BOTH':
                return @mysqli_fetch_array( $query, MYSQLI_BOTH );
                break;
        }
    }
}

Initial URL

                                

Initial Description

                                

Initial Title
php mysql/mysqli fetch array

Initial Tags
mysql, php, array

Initial Language
PHP