PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today!
  #1  
Old July 23rd, 2002, 11:46 AM
mhoward mhoward is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: UK
Posts: 49 mhoward User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
MySQL Table Dump

Can anyone help with the command for exporting the data within my MySQL table to a Microsoft Excel (csv) format splitting columns with a ","?

Reply With Quote
  #2  
Old July 23rd, 2002, 12:10 PM
CmdrDats CmdrDats is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: <br><img src='http://www.dats.co.za/icon.gif'>
Posts: 269 CmdrDats User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to CmdrDats Send a message via AIM to CmdrDats Send a message via Yahoo to CmdrDats
RE: MySQL Table Dump

Would a php script do the job, or do you mean command line?

Reply With Quote
  #3  
Old July 23rd, 2002, 12:51 PM
Taoism Taoism is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Winnipeg, MB, Canada
Posts: 81 Taoism User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 30 sec
Reputation Power: 2
RE: MySQL Table Dump

You can do this using the mysqldump utility.

I would encourage you to read up on it a bit more, but the syntax will be something like:

php Code:
Original - php Code
  1.  
  2. mysqldump --no-create-info --tab=<dir_to_dump_to> --fields-optionally-enclosed-by=<something> --fields-escaped-by=<something> --fields-terminated-by=<something> --lines-terminated-by=<something> db_name [table_name]


You should be able to find more info on mysqldump on the mysql.com website.

Cheers,
Keith.

Reply With Quote
  #4  
Old July 23rd, 2002, 12:57 PM
CmdrDats CmdrDats is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: <br><img src='http://www.dats.co.za/icon.gif'>
Posts: 269 CmdrDats User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to CmdrDats Send a message via AIM to CmdrDats Send a message via Yahoo to CmdrDats
RE: MySQL Table Dump

Wow, i didn't realize mysqldump was so flexible! I've always just assumed you simply dump structures and data in the "INSERT..." format to a text file and that was that..

Cool.

Reply With Quote
  #5  
Old July 23rd, 2002, 04:55 PM
mhoward mhoward is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: UK
Posts: 49 mhoward User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: MySQL Table Dump

A PHP script would be the answer I am looking for if possible

Reply With Quote
  #6  
Old July 23rd, 2002, 06:25 PM
Taoism Taoism is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Winnipeg, MB, Canada
Posts: 81 Taoism User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 30 sec
Reputation Power: 2
RE: MySQL Table Dump

How about this:
php Code:
Original - php Code
  1.  
  2. <?php
  3. //use a select like: SELECT * FROM <table>;
  4. //then, using mysql_fetch_array"
  5. while($holding[]=mysql_fetch_array());
  6.  
  7. //take away the last element which is not valid
  8. unset($holding[count($holding)-1);
  9.  
  10. //open the file to write out to...
  11.  
  12. //write out the column headers in CSV format
  13.  
  14. //build the array to write out...
  15. for($x=0,$y=count($holding);$x<$y;$x++){
  16.   $out_ara=implode(',',$holding[$x]);
  17.   $out_ara.="n";
  18.   //write out $out_ara to the file
  19. }
  20.  
  21. //now close the file
  22.  
  23. //you are done...
  24. ?>


Cheers,
Keith.

Reply With Quote
  #7  
Old July 23rd, 2002, 11:35 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: MySQL Table Dump

Quote:
php Code:
Original - php Code
  1.  
  2. <?php
  3.  
  4. //build the array to write out...
  5. for($x=0,$y=count($holding);$x<$y;$x++){
  6.   $out_ara=implode(',',$holding[$x]);
  7.   $out_ara.="n";
  8.   //write out $out_ara to the file
  9. }
  10. ?>


Well, just imploding with commas would not be enough. You also have to eliminate the new-line characters from the fields, embrace them with quotation marks and double the quotation marks inside the fields (according the the CSV format specifications). So the code would look sth like this:
php Code:
Original - php Code
  1.  
  2. <?php
  3.  
  4. function alter_field (&$value, $key) {
  5.  
  6.   $value = str_replace ('"', '""', $value);
  7.   //eliminating the new-lines
  8.   //i'm not really sure about this substitution
  9.   //so you should cnheck it somehow
  10.   $value = str_replace ("rn", 'n', $value);
  11.   //embracing with quotation marks
  12.   $value = '"' . $value . '"';
  13.  
  14. }
  15.  
  16. //build the array to write out...
  17. for($x=0,$y=count($holding);$x<$y;$x++){
  18.   array_walk ($holding[$x], 'alter_field');
  19.   $out_ara=implode(',',$holding[$x]);
  20.   $out_ara.="n";
  21.   //write out $out_ara to the file
  22. }
  23. ?>


Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > MySQL Table Dump


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

IBM developerWorks




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway