【发布时间】:2014-08-26 16:33:42
【问题描述】:
<?php
include("includes/config.php");
if ($_POST['frmCsv']) {
$strSelect = doSelectCsv();
header( 'Content-Type: text/csv' );
header( 'Content-Disposition: attachment;filename=export.csv' );
$strRow = mysql_fetch_assoc( $strSelect );
printArray($strRow);
if ( $strRow ) {
outputcsv( array_keys( $strRow ) );
}
while ( $strRow ) {
outputcsv( $strRow );
}
}
function doSelectCsv()
{
$strSql = "SELECT * FROM tbl_member";
$strResult = SelectQry($strSql);
}
function outputcsv( $fields )
{
$separator = '';
foreach ( $fields as $field ) {
echo $separator . $field;
$separator = ',';
}
}
?>
这是我从数据库中导出 csv 文件的代码。但它无法选择数据。选择查询无法正常工作。请帮帮我。
【问题讨论】:
-
SelectQry() 是做什么的?在 doSelectCsv() 上写
return并检查fputcsv -
与其编写自己的CSV writer,不如使用PHP内置的
fputcsv() function -
Read the red box 在每个
mysql_*页面上:扩展程序已弃用。不要再使用它了。使用替换:PDO或mysqli_*(其中i代表改进) -
我使用选择查询来选择数据库中的数据。我把 return 放在函数上,但它不能工作,先生。