mysql table to csv

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SSG001
    New Member
    • Oct 2007
    • 110

    mysql table to csv

    i want to create a csv file from a mysql table using php code
    can anybody give me example which will have date fields too

    Thanks in advance
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    See this tutorial with example export MySQL data to CSV PHP tutorial

    Ronald

    Comment

    • MarkSponge
      New Member
      • Apr 2008
      • 6

      #3
      Originally posted by SSG001
      i want to create a csv file from a mysql table using php code
      can anybody give me example which will have date fields too

      Thanks in advance
      If you already know the table structure why don't you just "select * from table" then iterate through the results and for each row add to a string variable. When the results are done write the string to a text file.

      In pseudocode:

      Code:
      $results = "select * from table";
      for(each result){
      $text .= field1.",".field2.",".field3."\n";
      }
      write $text to file
      If you do not know the table structure use nested loops:

      In pseudocode:

      Code:
      for(each row){
      for(each field){
      $text .= field.",";
      }
      $text .= "\n";
      }
      The comma after the field will cause problems but you get the idea.

      Comment

      Working...