Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. <?php
  2. $conn = mysql_connect("localhost","root","");
  3. mysql_select_db("phppot_examples",$conn);
  4.  
  5. $filename = "toy_csv.csv";
  6. $fp = fopen('php://output', 'w');
  7.  
  8. $query = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA='phppot_examples' AND TABLE_NAME='toy'";
  9. $result = mysql_query($query);
  10. while ($row = mysql_fetch_row($result)) {
  11. $header[] = $row[0];
  12. }
  13.  
  14. header('Content-type: application/csv');
  15. header('Content-Disposition: attachment; filename='.$filename);
  16. fputcsv($fp, $header);
  17.  
  18. $query = "SELECT * FROM toy";
  19. $result = mysql_query($query);
  20. while($row = mysql_fetch_row($result)) {
  21. fputcsv($fp, $row);
  22. }
  23. exit;
  24. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement