0

I have the following function in my php file, and my script is putting on CPanel. I am sure the script has been executed, as the last print out has appeared, however my csv file does not. I have changed the permission of folder Log_report to 755, but still file cannot be created, how can I make change? I am sure the mysql script to create csv is correct, as I used the same script in my XAMPP local machine and successfully created a file in my machine before.

function export($DB){
    $dbConnection = mysql_connect($DB['server'], $DB['loginName'], $DB['password']);
    if(!$dbConnection){
        die('Error! ' . mysql_error());
        }
    mysql_select_db($DB['database'], $dbConnection);
    $timezone = "Asia/Hong_Kong";
    if(function_exists('date_default_timezone_set')) 
        date_default_timezone_set($timezone);
    $Time = date('Y_m_d_H_i');
    $fileName = "/home/me/public_html/Log_Report/Report_".$Time.".csv";
    $result = mysql_query("SELECT TechName, ClientName, SiteName, LogTime, Type 
                            INTO OUTFILE '".$fileName."' 
                            FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED by '\"' 
                            LINES TERMINATED BY '\n' 
                            FROM tech AS T, client AS C, site AS S, log AS L 
                            WHERE T.TechID=L.TechID AND C.ClientID=L.ClientID AND S.SiteID=L.SiteID 
                            ORDER BY L.LogTime DESC");
    print "abcde";
}
3
  • Ive ran into similar issues with my works cpanel server. I think you will find you can make php create files in that folder just fine, its the write permissions on mysql that are likely problem. Pretty sure its restricted because sql injection + write privileges on mysql = creating malicious server side scripts above your site root.... Talk to your host Commented Aug 7, 2012 at 10:59
  • So if I want to create the file, I have to change the permission of mysql? May I ask is it possible to make changes on this configuration by myself? Commented Aug 8, 2012 at 1:47
  • You need to find out what the mysql service is running as. If its root (which I dont think it ahould be) then file write access shouldnt be an issue, otherwise it probably does need permission. If you have root access you can probably change it yourself but youre probably better off talking with youre host first as theres likely a good reason its restricted... Commented Aug 8, 2012 at 9:27

1 Answer 1

1

This thread should be helpful in explaining the mysql permission issue:

http://lists.mysql.com/mysql/206422

Also I should have asked what mysql user account you were running the query, as in root or another possibly limited user?

Sign up to request clarification or add additional context in comments.

4 Comments

another user insteadt of root
try exporting to /tmp/ and see if you can move it elsewhere from there. Also see here stackoverflow.com/questions/2783313/…
actually, I have solved this by changing the method of creating the files, but really thank you for your help, such reference can help me to learn more, so that I can solve it next time.
No problem. You should post your solution for other readers who come across this question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.