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";
}
Conrad
  • 933
  • 4
  • 19
  • 34
  • 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 – WebChemist Aug 07 '12 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? – Conrad Aug 08 '12 at 01: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... – WebChemist Aug 08 '12 at 09:27

1 Answers1

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?

WebChemist
  • 4,393
  • 6
  • 28
  • 37
  • another user insteadt of root – Conrad Aug 08 '12 at 10:04
  • 1
    try exporting to /tmp/ and see if you can move it elsewhere from there. Also see here http://stackoverflow.com/questions/2783313/how-can-i-get-around-mysql-errcode-13-with-select-into-outfile – WebChemist Aug 08 '12 at 10:15
  • 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. – Conrad Aug 09 '12 at 02:30
  • No problem. You should post your solution for other readers who come across this question – WebChemist Aug 09 '12 at 05:47