devans725 Posted March 21, 2008 Share Posted March 21, 2008 Hello, I am trying to save a MySql query to a file. I keep getting an Access Denied Error 1045. I have successfully displayed results of a query as HTML, so I know I am accessing the data ok. I have everything wide open just to try and make the script work, but I continue to get an Access Denied Error. I am not sure what else to check. Is this something my ISP is disabling? I currently do not have any other environment to test in besides at my ISP, trouble installing php on Vista. Following is my code. Any suggestions would be appreciated. <?php $con = mysql_connect("localhost","User","Password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("database_W2", $con); $state = $_POST["state"]; $gross = $_POST["gross"]; $result = mysql_query("SELECT * INTO OUTFILE '/share/wdat.csv' FROM employee_dat WHERE gross = '$gross' AND state = '$state';") or die(mysql_error()); echo "\nSQL Statement = $result <br>"; mysql_close($con); ?> Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted March 21, 2008 Share Posted March 21, 2008 i don't see any code attempting to write anything to file. assuming it's somewhere else, make sure the directory and file you are writing to have proper permissions. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted March 21, 2008 Share Posted March 21, 2008 Reading the manual to learn the conditions that the command works would help - The SELECT ... INTO OUTFILE 'file_name' form of SELECT writes the selected rows to a file. The file is created on the server host, so you must have the FILE privilege to use this syntax. file_name cannot be an existing file, which among other things prevents files such as /etc/passwd and database tables from being destroyed. As of MySQL 5.0.19, the character_set_filesystem system variable controls the interpretation of the filename. The SELECT ... INTO OUTFILE statement is intended primarily to let you very quickly dump a table to a text file on the server machine. 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. The server mentioned in the above is the mysql server. The client mentioned above is the web server/php script. Quote Link to comment Share on other sites More sharing options...
devans725 Posted March 21, 2008 Author Share Posted March 21, 2008 do you mind posting a URL to where you got your quote, I tried searching the manual, couldn't find anything, I have seen that explanation somewhere before, I do have a command that works at the command line, can't get it to run from script, <?php echo "select * from employee_dat where gross = \"38462\"" | mysql -uSername -pAssword hello_W2 > w2.txt; ?> I know I'm not looking in the right places, just need a little direction. I have googled the crap out of MySql query to file or any other combination there of. I am just please looking for the syntax to get this done. Thank you. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted March 21, 2008 Share Posted March 21, 2008 It's listed on the SELECT syntax page - http://dev.mysql.com/doc/refman/5.0/en/select.html Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.