From 2e061440560701f68dd2d65d8d56355f4bdfe6f4 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 22 Jan 2008 21:13:12 +0000 Subject: added enclosures to csv_from _result() --- system/database/DB_utility.php | 9 +++++---- user_guide/changelog.html | 4 +++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 9b78aa8ec..d9b8fed74 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -168,11 +168,12 @@ class CI_DB_utility extends CI_DB_forge { * * @access public * @param object The query result object - * @param string The delimiter - tab by default + * @param string The delimiter - comma by default * @param string The newline character - \n by default + * @param string The enclosure - double quote by default * @return string */ - function csv_from_result($query, $delim = "\t", $newline = "\n") + function csv_from_result($query, $delim = ",", $newline = "\n", $enclosure = '"') { if ( ! is_object($query) OR ! method_exists($query, 'field_names')) { @@ -184,7 +185,7 @@ class CI_DB_utility extends CI_DB_forge { // First generate the headings from the table column names foreach ($query->list_fields() as $name) { - $out .= $name.$delim; + $out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $name).$enclosure.$delim; } $out = rtrim($out); @@ -195,7 +196,7 @@ class CI_DB_utility extends CI_DB_forge { { foreach ($row as $item) { - $out .= $item.$delim; + $out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $item).$enclosure.$delim; } $out = rtrim($out); $out .= $newline; diff --git a/user_guide/changelog.html b/user_guide/changelog.html index a6a367b28..adbd500e9 100644 --- a/user_guide/changelog.html +++ b/user_guide/changelog.html @@ -92,6 +92,7 @@ Change Log
  • Added a check for NULL fields in the MySQL database backup utility.
  • Added "constrain_by_prefix" parameter to db->list_table() function. If set to TRUE it will limit the result to only table names with the current prefix.
  • Deprecated from Active Record; getwhere() for get_where(); groupby() for group_by(); havingor() for having_or(); orderby() for order_by; orwhere() for or_where(); and orlike() for or_like().
  • +
  • Modified csv_from_result() to output CSV data more in the spirit of basic rules of RFC 4180.
  • @@ -154,7 +155,8 @@ Change Log