简体   繁体   中英

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.

I am able to do it from database but I do not know how to export to Excel using PHP.

<?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.

See here for more information: http://php.net/fputcsv

$fp = fopen('file.csv', 'w');

while ($row = $results->fetchArray()) {
    fputcsv($fp, $row);
}
fclose($fp);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM