警告:include(../includes/db.php):无法打开流:

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41422033/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:23:39  来源:igfitidea点击:

Warning: include(../includes/db.php): failed to open stream:

php

提问by Raji

This is the problem I am facing now Can you please suggest me to get rid of this problem. Before I have not get this problem It was working nicely now I don't know what happened the path is correct only. Anyone please solve it...

这是我现在面临的问题,你能建议我摆脱这个问题吗?在我还没有遇到这个问题之前,它现在工作得很好,我不知道发生了什么,只是路径是正确的。请哪位大神解决一下...

Warning: include(../includes/db.php): failed to open stream: No such file or directory in C:\xampp\htdocs\portfolio\admin\includes\admin_header.php on line 3 Warning: include(): Failed opening '../includes/db.php' for inclusion (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\portfolio\admin\includes\admin_header.php on line 3 Warning: include(functions.php): failed to open stream: No such file or directory in C:\xampp\htdocs\portfolio\admin\includes\admin_header.php on line 4 Warning: include(): Failed opening 'functions.php' for inclusion (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\portfolio\admin\includes\admin_header.php on line 4

警告:include(../includes/db.php):无法打开流:C:\xampp\htdocs\portfolio\admin\includes\admin_header.php 中第 3 行没有这样的文件或目录警告:include():在第 3 行的 C:\xampp\htdocs\portfolio\admin\includes\admin_header.php 中打开包含 (include_path='C:\xampp\php\PEAR') 的 '../includes/db.php' 失败警告:包含(functions.php):无法打开流:第 4 行的 C:\xampp\htdocs\portfolio\admin\includes\admin_header.php 中没有这样的文件或目录警告:include():无法打开“functions.php”包含 (include_path='C:\xampp\php\PEAR') 在 C:\xampp\htdocs\portfolio\admin\includes\admin_header.php 第 4 行

回答by Kalyan Srinivas Limkar

Based on the error posted, it seems to be that the include_path is referring to the path (include_path='C:\xampp\php\PEAR') while the PHP files are included in some other folder.

根据发布的错误,include_path 似乎是指路径 (include_path='C:\xampp\php\PEAR'),而 PHP 文件包含在其他文件夹中。

You need to update the include_path variable to point to the correct location. You can find this in the php.ini file.

您需要更新 include_path 变量以指向正确的位置。您可以在 php.ini 文件中找到它。

回答by Flip Grav

I have had this the same issue before and it ended up being something dumb on my part i forgot to start the MySQL on the XAMPP control panel. I'm sure i'm late the the party on the answer but hope it can help someone later down the road.

我以前也遇到过同样的问题,结果我觉得很愚蠢,我忘了在 XAMPP 控制面板上启动 MySQL。我确定我迟到了答案,但希望它可以帮助后来的人。

回答by Millw0

a bit late but i just reply for those who might get the same error .

有点晚了,但我只是回复那些可能会遇到同样错误的人。

assuming you are storing header.php in your includes directory and its not beside your index.php,so when you include bd.php into your header.php and then including your header.php into your index.php pay attention that apache knows index.php direcotroy as your pwd so if you have set that relative path for db.php based on header.php directory its not gonna work.you can use absolute path to avoid this or just set you relative path based on relative location of db.php from index.php

假设您将 header.php 存储在您的包含目录中并且它不在您的 index.php 旁边,因此当您将 bd.php 包含到您的 header.php 中,然后将您的 header.php 包含到您的 index.php 中时,请注意 apache 知道索引.php direcotroy 作为你的密码,所以如果你根据 header.php 目录设置了 db.php 的相对路径,它不会工作。你可以使用绝对路径来避免这种情况,或者只是根据 db 的相对位置设置你的相对路径。来自 index.php 的 php

回答by Bright Onapito

This has to do with how you are coding your relative path. I am assuming you got this error when your app made reference to admin_header.php, which has an include()to try and call {document_root}/porfolio/admin/includes/db.php. My educated guess is it contains your implementation of the connection string to the database.

这与您如何编码相对路径有关。我假设当你的应用程序提到你得到这个错误admin_header.php,它有一个include()尝试和调用 {document_root}/porfolio/admin/includes/db.php。我有根据的猜测是它包含您对数据库的连接字符串的实现。

The correct relative path should be: include('../../includes/db.php');

正确的相对路径应该是: include('../../includes/db.php');

This link should give you a better understanding of relative paths (and paths in general). https://phpdelusions.net/articles/paths

此链接应该让您更好地了解相对路径(以及一般路径)。 https://phpdelusions.net/articles/paths

回答by Nit

It look likes, the files you are trying to include in your php codes, are not on that place. Try to save all your include files in a particular folder and then call it wherever you want to call it. suppose your index.php file is in xampp/htdocs/your_folder_name/index.php , then simply create a folder name whatever you want to name it inside your folder name your_folder_name/your_new_folder and save all your files which you want to include, as if you are saving db.php then call it on the top of your page as:

看起来,您尝试包含在 php 代码中的文件不在那个地方。尝试将所有包含文件保存在特定文件夹中,然后在您想要调用的任何地方调用它。假设您的 index.php 文件在 xampp/htdocs/your_folder_name/index.php 中,然后只需在文件夹名称 your_folder_name/your_new_folder 中创建一个文件夹名称,无论您想命名它什么,并保存您想要包含的所有文件,就好像您正在保存 db.php,然后在页面顶部将其调用为:

<?php include("your_new_folder/db.php");?>

回答by Charles

Try removing relative paths ("../") e.g. change include(../includes/db.php)to include(includes/db.php)

尝试删除相对路径 ( "../") 例如更改include(../includes/db.php)include(includes/db.php)

回答by funsholaniyi

Computers don't lie, if it says it doesn't see it, then it is not there

计算机不会说谎,如果它说它看不到它,那么它就不存在

Make sure you are making it look at the right place, and if I will advise you do it manually also to confirm

确保你让它看起来在正确的地方,如果我会建议你手动做也是为了确认

I also suspect it is an issue arising from using relative paths. Please make sure the path is right considering where you are currently calling the file from

我也怀疑这是使用相对路径引起的问题。考虑到您当前从何处调用文件,请确保路径正确

e.g calling include(../includes/db.php) from index.php is different from calling it from admin/index.php

例如从 index.php 调用 include(../includes/db.php) 不同于从 admin/index.php 调用它

EDIT

编辑

If your are calling from C:\xampp\htdocs\portfolio\admin\includes\admin_header.php to C:\xampp\htdocs\portfolio\includes

如果您从 C:\xampp\htdocs\portfolio\admin\includes\admin_header.php 调用到 C:\xampp\htdocs\portfolio\includes

then

然后

include(../../includes/db.php);

is the right syntax to use

是正确的语法使用

Hope this Helps

希望这可以帮助