Jump to content

PHP, MySQL, INTO OUTFILE


devans725

Recommended Posts

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);
?>

   

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.