开发者社区 问答 正文

如何将mysqli转换为PDO


$csv  = "CSV File" . "-" . date('Y-m-d-his') . '.csv';
$file = fopen($_SERVER['DOCUMENT_ROOT'] . '/cache/' . $csv, 'w');
// Get the table
if (!$result = mysqli_query($dbcon, $query))
    printf("Error: %s\n", $mysqli->error);
    // Get column names 
    while ($column = mysqli_fetch_field($result)) {
        $column_names[] = $column->name;
    }

    // Write column names in csv file
    if (!fputcsv($file, $column_names))
        die('Can\'t write column names in csv file');

    // Get table rows
    while ($row = mysqli_fetch_row($result)) {
        // Write table rows in csv files
        if (!fputcsv($file, $row))
            die('Can\'t write rows in csv file');
    }
fclose($file);

展开
收起
社区秘书 2019-12-09 16:52:55 541 分享 版权
0 条回答
写回答
取消 提交回答
问答地址: