download table data from mysql

Reply

Join Date: Oct 2007
Posts: 15
Reputation: nikhita is an unknown quantity at this point 
Solved Threads: 0
nikhita nikhita is offline Offline
Newbie Poster

download table data from mysql

 
0
  #1
Mar 26th, 2008
how to download table data from mysql table using php other than files
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 154
Reputation: Suomedia is an unknown quantity at this point 
Solved Threads: 19
Suomedia Suomedia is offline Offline
Junior Poster

Re: download table data from mysql

 
0
  #2
Mar 26th, 2008
The simplest way to download table data is to use phpMyAdmin.


Matti Ressler
Suomedia
If you want your dreams to come true, the first thing you must do is to wake up....
Suomedia - Dynamic Content Management
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 60
Reputation: RoryGren is an unknown quantity at this point 
Solved Threads: 8
RoryGren's Avatar
RoryGren RoryGren is offline Offline
Junior Poster in Training

Re: download table data from mysql

 
0
  #3
Mar 26th, 2008
You need to give a little more information - what do you want to do with the data? Display it in a table on a web page or just make a text backup?
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 15
Reputation: nikhita is an unknown quantity at this point 
Solved Threads: 0
nikhita nikhita is offline Offline
Newbie Poster

Re: download table data from mysql

 
0
  #4
Mar 27th, 2008
I want to download the data as a text fille.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 60
Reputation: RoryGren is an unknown quantity at this point 
Solved Threads: 8
RoryGren's Avatar
RoryGren RoryGren is offline Offline
Junior Poster in Training

Re: download table data from mysql

 
0
  #5
Mar 27th, 2008
Then I agree with Suomedia. I use SQLYog, though. It's a really nice query analyser type tool that you install on your local PC. It will allow you to do almost anything with your database.

www.webyog.com - there is an enterprise edition and a freebie community edition.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 15
Reputation: nikhita is an unknown quantity at this point 
Solved Threads: 0
nikhita nikhita is offline Offline
Newbie Poster

Re: download table data from mysql

 
0
  #6
Mar 31st, 2008
I would like to know whether all the data in the database/table can be available in a text file without the sql queries in it...
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 154
Reputation: Suomedia is an unknown quantity at this point 
Solved Threads: 19
Suomedia Suomedia is offline Offline
Junior Poster

Re: download table data from mysql

 
0
  #7
Mar 31st, 2008
Yes. If you use phpmyadmin you will see it as export options in many formats. One that I commonly use is CSV.


Matti Ressler
Suomedia
If you want your dreams to come true, the first thing you must do is to wake up....
Suomedia - Dynamic Content Management
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 15
Reputation: nikhita is an unknown quantity at this point 
Solved Threads: 0
nikhita nikhita is offline Offline
Newbie Poster

Re: download table data from mysql

 
0
  #8
Mar 31st, 2008
is it possible using PHP code. because I want the user to download the data from the database as a text file. The concept is, user can enter some data in the database and whenever they wants, they could download it as a text file.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 154
Reputation: Suomedia is an unknown quantity at this point 
Solved Threads: 19
Suomedia Suomedia is offline Offline
Junior Poster

Re: download table data from mysql

 
0
  #9
Mar 31st, 2008
Yes, of course it can be done with php. Its quite a bit of code which I don't have the time for, but I am sure somebody else probably will. The web is full of tutorials on how to do this.


Matti Ressler
Suomedia
If you want your dreams to come true, the first thing you must do is to wake up....
Suomedia - Dynamic Content Management
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 11
Reputation: trochia is an unknown quantity at this point 
Solved Threads: 0
trochia trochia is offline Offline
Newbie Poster

Re: download table data from mysql

 
0
  #10
Mar 2nd, 2009
For future reference for others, this will download as *.csv file. You may change file type and HEADER types, for *.txt

I do not use (or download) any *.txt, so I have not reseached modifying.
  1. <?php
  2. $host = 'localhost';
  3. $user = 'dbUsername';
  4. $pass = 'dbPassword';
  5. $db = 'dbName';
  6. $table = 'dbTable';
  7. $file = 'export';
  8.  
  9. $link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error());
  10. mysql_select_db($db) or die("Can not connect.");
  11.  
  12. $result = mysql_query("SHOW COLUMNS FROM ".$table."");
  13. $i = 0;
  14. if (mysql_num_rows($result) > 0) {
  15. while ($row = mysql_fetch_assoc($result)) {
  16. $csv_output .= $row['Field']."; ";
  17. $i++;
  18. }
  19. }
  20. $csv_output .= "\n";
  21.  
  22. $values = mysql_query("SELECT * FROM ".$table."");
  23. while ($rowr = mysql_fetch_row($values)) {
  24. for ($j=0;$j<$i;$j++) {
  25. $csv_output .= $rowr[$j]."; ";
  26. }
  27. $csv_output .= "\n";
  28. }
  29.  
  30. $filename = $file."_".date("Y-m-d_H-i",time());
  31. header("Content-type: application/vnd.ms-excel");
  32. header("Content-disposition: csv" . date("Y-m-d") . ".csv");
  33. header( "Content-disposition: filename=".$filename.".csv");
  34. print $csv_output;
  35. exit;
  36. ?>
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC