致命错误:require_once()[function.require]:无法开口要求“__DIR__ [英] Fatal error: require_once() [function.require]: Failed opening required '__DIR__

查看:2469
本文介绍了致命错误:require_once()[function.require]:无法开口要求“__DIR__的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的PHP和Android。我一直试图找到现有的线程解决方案,但没有成功。

我工作的一个机器人项目中,我需要连接到外部数据库。我已经成功地创建一个使用WAMP外部数据库,并将其在本地主机工作得很好。

现在我试图让外部数据库在线和我使用的000webhost.com。
我已经通过000webhost.com服务,并试图通过我的scrips,而且000webhost.com与为我提供的凭据连接到数据库创建了数据库的副本。 (DB_HOST,DB_USER等...)

我应该显示所有现有用户的脚本。即它应该所有信息从DB连接到数据库,并显示在Web浏览器中(我通过网络连接到的http://www.mywampserver.netau.net/android_connect/get_all_users_placedescoverer.php),但它失败,出现以下错误:

 警告:require_once(__ __ DIR / android_connect / db_connect_placedescoverer.php)
[function.require一次]:未能打开流:在没有这样的文件或目录
/home/a2056935/public_html/android_connect/get_all_users_placedescoverer.php
第12行

在我的第12行get_all_users_placedescoverer.php我有:

  require_once __DIR__。 /android_connect/db_connect_placedescoverer.php';

db_connect_placedescoverer.php 存在于同一文件夹 et_all_users_placedescoverer.php

我也试着使用方法:

<$p$p><$c$c>require_once(realpath(dirname(__FILE__)'/android_connect/db_connect_placedescoverer.php'));

但后来我得到:


  

警告:require_once()一次function.require]:文件名不能在第13行/home/a2056935/public_html/android_connect/get_all_users_placedescoverer.php空


在这一个帮助将是非常美联社preciated。


解决方案

的问题是PHP版本

魔术常量 __ __ DIR 仅作为PHP v.5.3.0的,如在的 文档

000webhost的可能是使用较低版本。

创建具有code文件的phpinfo(); 在网络服务器和检查的PHP版本

要事先确定在一个PHP bersion使用脚本5.3.0,变线12:

  $ DIR =目录名(__ FILE__);require_once $目录。 /android_connect/db_connect_placedescoverer.php';

编辑:

你确定你在正确的地方的文件?该文件应该是一个叫做android_connect目录内的地方。

试着用你的文件的相对路径从你调用所在的需要。

如果您的index.php(我假设的index.php是要求其他PHP文件中的文件)放在public_html目录然后尝试使用相对路径

  require_once'android_connect / db_connect_placedescoverer.php';

如果他们是在同一个文件夹中,然后你可以使用的文件名:

  require_once'db_connect_placedescoverer.php';

I'm new to PHP and Android. I've tried to find a solution on existing threads, but no success.

I'm working on an android project in which I need to connect to external database. I've managed to create an external database using WAMP and it worked fine on a localhost.

Now I'm trying to get the external DB online and I'm using the 000webhost.com. I've created a copy of my database via 000webhost.com services and trying to connect to the DB via my scrips and the credentials that the 000webhost.com provided me with. (DB_HOST, DB_USER and etc...)

I have a script that should display all existing users. i.e. it should connect to the DB and display in web browser all the information from the DB (I'm connecting through web to http://www.mywampserver.netau.net/android_connect/get_all_users_placedescoverer.php), but it fails with the following error:

Warning: require_once(__DIR__/android_connect/db_connect_placedescoverer.php)
[function.require-once]: failed to open stream: No such file or directory in 
/home/a2056935/public_html/android_connect/get_all_users_placedescoverer.php
on line 12

In my get_all_users_placedescoverer.php in line 12 i have:

require_once __DIR__ . '/android_connect/db_connect_placedescoverer.php';

And db_connect_placedescoverer.php exists in the same folder as et_all_users_placedescoverer.php.

I've also tried to use:

require_once(realpath(dirname(__FILE__)'/android_connect/db_connect_placedescoverer.php'));

but then i get:

Warning: require_once() [function.require-once]: Filename cannot be empty in /home/a2056935/public_html/android_connect/get_all_users_placedescoverer.php on line 13

A help on this would be highly appreciated.

解决方案

The problem is the PHP Version

The magic constant __DIR__ is only available as of PHP v.5.3.0, as stated in the documentation

000webhost is probably using a lower version.

Create a file with the code phpinfo(); in the webserver and check php version.

To fix the script for usage in a php bersion prior to 5.3.0, change line 12 to:

$dir = dirname(__FILE__);

require_once $dir . '/android_connect/db_connect_placedescoverer.php';

EDIT:

Are you sure you have the file in the right place? The file should be place inside a directory called android_connect.

Try using the relative path to your file from where you're calling the require.

If your index.php (i'm assuming index.php is the file requiring the other php file) is placed in public_html directory then try using the relative path

require_once 'android_connect/db_connect_placedescoverer.php';

If they are in the same folder then you can just use the file name:

require_once 'db_connect_placedescoverer.php';

这篇关于致命错误:require_once()[function.require]:无法开口要求“__DIR__的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆