Exporting data into a text file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Claus Mygind
    Contributor
    • Mar 2008
    • 571

    #1

    Exporting data into a text file

    I have been able to create a text file on the MySQL host server using this technique.

    The SELECT ... INTO OUTFILE statement is intended primarily to let you very quickly dump a table to a text file on the server machine.
    However is there a way to progromatically incorporate the following into an application.

    If you want to create the resulting file on some client host other than the server host, you cannot use SELECT ... INTO OUTFILE. In that case, you should instead use a command such as mysql -e "SELECT ..." > file_name to generate the file on the client host.
    My application is a client web app. The user calls the web server executes the program and I would like the resulting .txt file to be stored on one of our network drives other than the MySQL data server.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Which programming language?

    Comment

    • Claus Mygind
      Contributor
      • Mar 2008
      • 571

      #3
      well you will not believe it but dBase. I think I finally got the answer to my question however.

      First I tried something which is not very sound. I granted the user file privilege, which of course is too grand. So not being happy with that I went back to the drawing board.

      As this is a web application, I determined that I could export the data into notepad in a text format and the user can save the data right on their desktop computer (client). Here is my code.
      Code:
      puts("Content-type: application/vnd.ms-notepad")
      puts("Content-Disposition: filename='test.txt'")
      puts('')
      do
      c1 = f[1].value 
      c2 = f[2].value 
      c3 = f[3].value 
      c4 = f[4].value 
      c5 = f[5].value 
      cValue = ["]+c1+[","]+c2+[","]+c3+[",]+c4+[,]+c5
      puts( cValue )
      until not q.rowset.next()
      In this example I output 3 alphanumeric fields (text strings) and two numeric fields. and it works beautifully.

      So thanks for your offer of help.

      Comment

      Working...