[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cobalt-developers] Interbase .gdb to .txt or .csv from ASP webpage?



"Todd Kirk" <tkirk@xxxxxxxxxxxxxx> wrote:
> Anyone know how I could get a .gdb Interbase database file to
> output to a .txt or .csv file for a client that wants the data to import
> into Ms Excel?

I do very little programming in ASP, but I know how to do it in PHP.  See
code below:

$qs = "SELECT * FROM table ";
$rs = ibase_query( $qs );
$num_fields = ibase_num_fields( $rs );

// Change to "," if want comma-delimited.
// Tab-delimited "\t" should viewable automatically by Excel without its
wizard.
$delimiter = "\t";

while ( $qd = ibase_fetch_object ( $rs ) )
{
 for ( $i = 0; $i < $num_fields; $i++ )
 {
  $output .= $qd[$i];

  if ( $i < $num_fields - 1 )
  {
   $output .= $delimiter;
  }
  else
  {
   $output .= "\n";
  }
 }

}

echo $output;

// If for some reason you need the column names
// the code below should help (lifted from a program I wrote).

// Get column names.
$qs = "SELECT * FROM table";
$rs = ibase_query( $qs );
$num_fields = ibase_num_fields( $rs );

for ( $i = 0; $i < $num_fields; $i++ )
{
    $field_info = ibase_field_info( $rs, $i );
    $field_names[] = $field_info["name"];
}

// Generate comma-separated list of fields.
$field_list = implode( ",", $field_names );

> Specifically I would like them to simply login to their admin
> area and click a link to download a .txt or .csv file.

If you can't figure out how to do it in ASP and PHP can't be used directly
you could always run the PHP script from a cron job to generate the output
files periodically which then can be downloaded by clicking a hyperlink.
Creating a file based on the output is easy so if you don't know how to do
that check references online.

--
Steve Werby
President, Befriend Internet Services LLC
http://www.befriend.com/