943,627 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 3053
  • PHP RSS
Mar 26th, 2008
0

download table data from mysql

Expand Post »
how to download table data from mysql table using php other than files
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nikhita is offline Offline
15 posts
since Oct 2007
Mar 26th, 2008
0

Re: download table data from mysql

The simplest way to download table data is to use phpMyAdmin.


Matti Ressler
Suomedia
Reputation Points: 15
Solved Threads: 19
Junior Poster
Suomedia is offline Offline
154 posts
since Mar 2008
Mar 26th, 2008
0

Re: download table data from mysql

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?
Reputation Points: 12
Solved Threads: 8
Junior Poster in Training
RoryGren is offline Offline
60 posts
since Oct 2007
Mar 27th, 2008
0

Re: download table data from mysql

I want to download the data as a text fille.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nikhita is offline Offline
15 posts
since Oct 2007
Mar 27th, 2008
0

Re: download table data from mysql

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.
Reputation Points: 12
Solved Threads: 8
Junior Poster in Training
RoryGren is offline Offline
60 posts
since Oct 2007
Mar 31st, 2008
0

Re: download table data from mysql

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...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nikhita is offline Offline
15 posts
since Oct 2007
Mar 31st, 2008
0

Re: download table data from mysql

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
Reputation Points: 15
Solved Threads: 19
Junior Poster
Suomedia is offline Offline
154 posts
since Mar 2008
Mar 31st, 2008
0

Re: download table data from mysql

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nikhita is offline Offline
15 posts
since Oct 2007
Mar 31st, 2008
0

Re: download table data from mysql

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
Reputation Points: 15
Solved Threads: 19
Junior Poster
Suomedia is offline Offline
154 posts
since Mar 2008
Mar 2nd, 2009
0

Re: download table data from mysql

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.
php Syntax (Toggle Plain Text)
  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. ?>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
trochia is offline Offline
12 posts
since Jan 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Creating a 6 digit number from letters
Next Thread in PHP Forum Timeline: PHP and Checkboxes in email





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC