Trouble using OUTPUT INTO in mysql

Discussion in 'Databases' started by Darden12, Sep 23, 2011.

  1. #1
    I have a mysql query written in PHP as follows:

    SELECT * FROM table OUTPUT INTO 'test.txt'
    PHP:
    Now, that query actually works, but I don't know where to find the file on the server.

    And, whenever I try to specify the output address, as in:

    SELECT * FROM table OUTPUT INTO '/var/lib/mysql/data/public/test.txt'
    PHP:
    I get error codes.

    Looking for advice on how I can both run the query successfully AND locate the file that it outputs.

    Thanks,
    BRian
     
    Solved! View solution.
    Darden12, Sep 23, 2011 IP
  2. gvre

    gvre Member

    Messages:
    35
    Likes Received:
    6
    Best Answers:
    3
    Trophy Points:
    33
    #2
    Try
    SELECT [COLOR=#339933]*[/COLOR] FROM table OUTPUT INTO [COLOR=#0000FF]'/tmp/test.txt'[/COLOR]
    Code (markup):
     
    gvre, Sep 24, 2011 IP
  3. Darden12

    Darden12 Well-Known Member

    Messages:
    107
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #3
    Thanks, but the problem is I'm on a shared hosting plan and I can't even locate the tmp directory to retrieve the file.

    The point is moot, anyway, because when I try /tmp/test.txt
    I just get an error code.

    When I use 'test.txt', the statement works -- but again, I can't find the "test.txt" file on any of the directories available to me in my shared hosting plan.
     
    Last edited: Sep 24, 2011
    Darden12, Sep 24, 2011 IP
  4. gvre

    gvre Member

    Messages:
    35
    Likes Received:
    6
    Best Answers:
    3
    Trophy Points:
    33
    #4
    Try this

    $dest = dirname(__FILE__);
    $sql  = "SELECT * FROM table INTO OUTFILE '$dest/test.txt'";
    mysql_query($sql) || die(mysql_error());
    
    Code (markup):
     
    gvre, Sep 24, 2011 IP
  5. Darden12

    Darden12 Well-Known Member

    Messages:
    107
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #5
    I get the following error message when I run the code:

    Errcode: 13

    I guess it's either a permissions issue or due to some feature that my shared hosting provider has disabled "for security reasons"

    The odd thing is, I don't get an error message with
    The only problem is-- I don't know where it's sending the file. I can't find it on the directories that my shared hosting provider lets me see via FTP.
     
    Last edited: Sep 25, 2011
    Darden12, Sep 25, 2011 IP
  6. #6
    Error 13 means "permission denied". Try to add write perms (chmod 777) the folder of you script and try again.
    When using 'test.txt', the file's directory is mysql data dir.
     
    gvre, Sep 25, 2011 IP
  7. Darden12

    Darden12 Well-Known Member

    Messages:
    107
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #7
    That's done it. It works great after changing permissions and using your suggested script.

    Thanks for the help!!!
     
    Darden12, Sep 25, 2011 IP