可悲的是,没有办法将参数传递给函数csv_from_result
并避免列名,但您可以csv_from_result
根据原始函数的代码构建自定义函数并删除不需要的部分:
/**
* Generate CSV from a query result object
*
* @param object $query Query result object
* @param string $delim Delimiter (default: ,)
* @param string $newline Newline character (default: \n)
* @param string $enclosure Enclosure (default: ")
* @return string
*/
function my_custom_csv_from_result($query, $delim = ',', $newline = "\n", $enclosure = '"')
{
if ( ! is_object($query) OR ! method_exists($query, 'list_fields'))
{
show_error('You must submit a valid result object');
}
$out = '';
// Blast through the result array and build out the rows
while ($row = $query->unbuffered_row('array'))
{
foreach ($row as $item)
{
$out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $item).$enclosure.$delim;
}
$out = substr(rtrim($out), 0, -strlen($delim)).$newline;
}
return $out;
}
该代码基于csv_from_result
从此处获取的实现:https ://github.com/EllisLab/CodeIgniter/blob/develop/system/database/DB_utility.php