开发者社区> 问答> 正文

如何将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 518 0
0 条回答
写回答
取消 提交回答
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载