You are here

function phpexcel_export_db_result in PHPExcel 6

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. 7.3 phpexcel.inc \phpexcel_export_db_result()
  4. 7 phpexcel.api.inc \phpexcel_export_db_result()
  5. 7.2 phpexcel.inc \phpexcel_export_db_result()

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 MySQL 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.api.inc, line 128
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);
}