我是靠谱客的博主 欣慰大神,这篇文章主要介绍pdo mysql fetchall_将结果从PDO::fetchAll()转换为数组,现在分享给大家,希望可以做个参考。

发现这一点,天知道在哪里,很久以前就完成了这个任务。我希望你觉得这对你有帮助:

/**

* Formats a line (passed as a fields array) as CSV and returns the CSV as a string.

* Adapted from http://us3.php.net/manual/en/function.fputcsv.php#87120

*/

function arrayToCsv( array &$fields, $delimiter = ';', $enclosure = '"', $encloseAll = false, $nullToMysqlNull = false ) {

$delimiter_esc = preg_quote($delimiter, '/');

$enclosure_esc = preg_quote($enclosure, '/');

$output = array();

foreach ( $fields as $field ) {

if ($field === null && $nullToMysqlNull) {

$output[] = 'NULL';

continue;

}

// Enclose fields containing $delimiter, $enclosure or whitespace

if ( $encloseAll || preg_match( "/(?:${delimiter_esc}|${enclosure_esc}|s)/", $field ) ) {

$output[] = $enclosure . str_replace($enclosure, $enclosure . $enclosure, $field) . $enclosure;

}

else {

$output[] = $field;

}

}

return implode( $delimiter, $output );

}

最后

以上就是欣慰大神最近收集整理的关于pdo mysql fetchall_将结果从PDO::fetchAll()转换为数组的全部内容,更多相关pdo内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(142)

评论列表共有 0 条评论

立即
投稿
返回
顶部