MySQL数据库到.txt文件
问题描述:
我想将来自我的mysql数据库的所有电子邮件地址都放在一个文本文件中. 每当有一个新的注册时,我都会创建一个, 所以通常我应该将此代码放在我的register.php中:
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:
(连接到数据库后):
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?
谢谢!
答
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