You are here

function phpexcel_export_db_result in PHPExcel 7.3

Same name and namespace in other branches
  1. 8.3 phpexcel.inc \phpexcel_export_db_result()
  2. 6.2 phpexcel.api.inc \phpexcel_export_db_result()
  3. 6 phpexcel.api.inc \phpexcel_export_db_result()
  4. 7 phpexcel.api.inc \phpexcel_export_db_result()
  5. 7.2 phpexcel.inc \phpexcel_export_db_result()

Export a database result to an Excel file.

Simple API function which allows to export a db_query() result to an Excel file. The headers will be set to the names of the exported columns.

Parameters

result $result: The database result object.

string $path: The path where the file should be saved. Must be writable.

array $options: An array which allows to set some specific options.

Return value

bool TRUE on success, FALSE on error. Look into watchdog logs for information about errors.

See also

phpexcel_export()

1 call to phpexcel_export_db_result()
PHPExcelTest::testDBResultExport in tests/phpexcel.test
Test db_result export.

File

./phpexcel.inc, line 195
Defines the phpexcel api functions that other modules can use.

Code

function phpexcel_export_db_result($result, $path, $options = array()) {
  $data = array();
  while ($row = $result
    ->fetchAssoc()) {
    if (!isset($headers)) {
      $headers = array_keys($row);
    }
    $data[] = array_values($row);
  }
  return phpexcel_export($headers, $data, $path, $options);
}