summaryrefslogtreecommitdiffstats
path: root/system/database/DB_utility.php
diff options
context:
space:
mode:
authorDerek Jones <derek.jones@ellislab.com>2008-01-22 22:13:12 +0100
committerDerek Jones <derek.jones@ellislab.com>2008-01-22 22:13:12 +0100
commit2e061440560701f68dd2d65d8d56355f4bdfe6f4 (patch)
tree8949cbe20d60461f3ee3e74a771b9726a925bbbb /system/database/DB_utility.php
parent77fee9affdd28c647759965aec20028aeb1d8798 (diff)
added enclosures to csv_from _result()
Diffstat (limited to 'system/database/DB_utility.php')
-rw-r--r--system/database/DB_utility.php9
1 files changed, 5 insertions, 4 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;