简体   繁体   English

php&mysql fopen无法打开文件

[英]php&mysql fopen cannot open the file

I am using PHP & MySQL to generate a dynamic web page. 我正在使用PHP和MySQL生成动态网页。 Now I want to make the search result into a file. 现在,我要将搜索结果放入文件中。 Firstly, I use 首先,我用

 $query = "select * from database into outfile 'query.txt'";@mysql($query);

BUt it cannot work; 但是,它无法正常工作; Then, I try to use the "fopen" function. 然后,我尝试使用“打开”功能。

$fp=fopen("query.txt","w+") or exit("Unable to open file!");
if($result_specific){
while( $row = mysql_fetch_array( $result_specific,MYSQL_ASSOC )){
    echo fwrite($fp,$row["p1"]."\t".$row["p2"]."\t".$row["p3"]."\n");
}
}
fclose($fp);

Unfortunately, it tells me "Unable to open file!". 不幸的是,它告诉我“无法打开文件!”。 Maybe it is a wrong Url? 也许是错误的网址? But I don't know how to specify the correct URL. 但是我不知道如何指定正确的URL。

select * from database into outfile 'query.txt' 从数据库中选择*到outfile'query.txt'中

You haven't specified a path - only a filename. 您尚未指定路径-仅指定文件名。 The file will be written to the current working directory of the MySQL instance. 该文件将被写入MySQL实例的当前工作目录。 It will be written with the uid of the the user running the instance. 它将使用运行实例的用户的uid编写。 It's impossible to say from the information you've provided what permissions the resultant file will have - on a Linux/BSD/Posix system the permissions will be based on he the umask inherited by the DBMS instance. 从您提供的信息中无法说出结果文件将具有哪些权限-在Linux / BSD / Posix系统上,权限将基于DBMS实例继承的umask。

$fp=fopen("query.txt","w+") $ fp = fopen(“ query.txt”,“ w +”)

Is you PHP looking in the right directory? 您在寻找正确目录中的PHP吗? What are the permissions on the file? 该文件有哪些权限?

or exit("Unable to open file!"); 或退出(“无法打开文件!”);

That 'or' will not do what you think it does - should be '||' “或”将不会执行您认为的操作-应该为“ ||”

if($result_specific){ ... if($ result_specific){...

What has this got to do with the problem? 这与问题有什么关系?

Go back and use full paths and check the permissions. 返回并使用完整路径并检查权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM