drvfqr5609
2015-08-12 20:36
浏览 61
已采纳

使用php包含层次结构中不同级别的文件

I am creating a browser/text-based game. In order to organize the files, I broke them down into different folders

Game

Server //DB Connection Files
Styles //CSS Files
Structure //Any Template files for the viewable pages (menu bars, etc that I don't want to copy in each viewable .php**
Scripts //JS Files
Location Folders // Like 'Work' or 'Crime' - the menu options

If I'm in say localhost/game/work/work.php and want to access the database, I would have to use

include "../../server/dbc.php";

I have tried

$root = dirname(__file__);

in my localhost/game folder before, but it started giving me an error - "failed to open stream: no suitable wrapper could be found" which is because it's using a full file location and you apparently can't do that.

Is there an easier way to make it so I can access my DB from anywhere regardless of hierarchy in the folders?

Thank you in advance!

图片转代码服务由CSDN问答提供 功能建议

我正在创建一个基于浏览器/文本的游戏。 为了整理文件,我将它们分成不同的文件夹

游戏

< p>服务器//数据库连接文件
样式// CSS文件
结构//可查看页面的任何模板文件(菜单栏等我不想在每个可查看的文件中复制。 php **
脚本// JS文件
位置文件夹//喜欢'工作'或'犯罪' - 菜单选项

如果我说 localhost / game / work / work.php 并想要访问数据库,我将不得不使用

  include“../../server/dbc.php";
nn

我试过了

  $ root = dirname(__ file __); 
   
 
 

localhost / game 文件夹之前, 但它开始给我一个错误 - “无法打开流:找不到合适的包装器”,这是因为它使用的是完整的文件位置而你显然可以' 这样做。

是否有一种更简单的方法可以使我无论文件夹中的层次结构如何都能从任何地方访问我的数据库?

谢谢 你提前!

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dtwr2012 2015-08-12 20:45
    已采纳

    There are a many options, I'll provide a few in order of ease of implementation:

    打赏 评论

相关推荐 更多相似问题