开发者

Mysql database to .txt file

I want to put al the emailaddresses from my mysql database in a text file. I would to create this each time some one new is registered, so normally; I should put this code in my register.开发者_高级运维php:

(after connecting to the database):

mysql_query("SELECT mail FROM users INTO OUTFILE 'test.txt'") or die("failed");

But I always get the "failed". What is wrong in this code, or is there an other way?

Thanks!


Francis,

A much simpler method to do this would be to simply execute the query from the shell:

mysql databasename -e "SELECT mail FROM users" > test.txt


Maybe you could use a query select all the data you want, than create a textfile and save that using PHP.


Do you know what directory you are writing the file into?

The user you connect to mysql as will need to be able to write a file into this directory.

man chmod

to see how to change permissions. You will probably need at least something like chmod u+w for the user in question.


You need to create the file with write permission (rw_r_rw) before executing the mysql query. In php this is done like this:

$file= 'test.txt';
touch($file);
chmod($file, 0646);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜