[英]Exporting SQLite table to Excel using PHP script
I am working on a project and new to PHP and I need to know how to export the table data from SQLite to Excel. 我正在开发一个项目,并且是PHP的新手,我需要知道如何将表数据从SQLite导出到Excel。
I am able to do it from database but I do not know how to export to Excel using PHP. 我可以从数据库中执行此操作,但是我不知道如何使用PHP导出到Excel。
<?php
$db = new sqlite3('I:\Preeti\explor\WebMobility.db');
$results = $db->query('SELECT * FROM VerbaliData');
while ($row = $results->fetchArray()) {
var_dump($row);
}
?>
The easiest method whould be to write your results into a CSV file which opens in Excel in a readable format. 最简单的方法是将结果写入CSV文件,该文件在Excel中以可读格式打开。
See here for more information: http://php.net/fputcsv 有关更多信息,请参见此处: http : //php.net/fputcsv
$fp = fopen('file.csv', 'w');
while ($row = $results->fetchArray()) {
fputcsv($fp, $row);
}
fclose($fp);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.