Advertisement
metalx1000

PHP sqlite3 to CSV

Jun 8th, 2023
1,330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.20 KB | None | 0 0
  1. <?php
  2. // Copyright (C) 2023 Kris Occhipinti
  3. // https://filmsbykris.com
  4. //
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the GNU Affero General Public
  7. // License as published by the Free Software Foundation;
  8. // version 3 of the License.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. // Affero General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Lesser General Public License
  16. // along with this program; if not, write to the Free Software Foundation,
  17. // Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  18. // https://www.gnu.org/licenses/agpl-3.0.txt
  19. header('Content-Type: text/csv');
  20. header('Content-Disposition: attachment; filename="tshirt-orders.csv"');
  21. $db = new SQLite3('db/orders.db');
  22. $results = $db->query('SELECT * FROM orders');
  23. $data = array();
  24. echo "Order Number,Name,Email,s,m,l,xl,xxl,picked up,paid,style,xxxl,xxxxl\n";
  25. while ($row = $results->fetchArray(SQLITE3_ASSOC)) {
  26. echo implode(array_values($row), ",") . "\n";
  27. }
  28.  
  29. ?>
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement