文件包含php中的错误

时间:2013-12-22 21:32:04

标签: php include

我有这个文件结构并遇到两个错误:

php-
    |
    |=objects
    |    |=account.php
    |
    |=data_access
    |    |=connect_to_db.php
    |    |=query.php
    |    |=db_schema.php 

logic-
    |
    |=account_page.php

第一个错误:现在在account_page.php我包含了这个:

include_once'D:\Development\xampp\htdocs\account_share\php\data_access\query.php';
include_once '../data_access/connect_to_db.php';

完整路径正常,但第二个错误: 警告:include_once(../ data_access / connect_to_db.php):无法打开流:第3行的D:\ Development \ xampp \ htdocs \ account_share \ php \ logic \ accounts_page.php中没有此类文件或目录

   Warning: include_once(): Failed opening '../data_access/connect_to_db.php' for inclusion (include_path='.;D:\Development\xampp\php\PEAR') in D:\Development\xampp\htdocs\account_share\php\logic\accounts_page.php on line 3

db_schema.php中的第二个错误:我有这个数组:

    $schema['user_account']['table'] = "t_user_account";
    $schema['user_account']['user_id'] = "f_userId";
    $schema['user_account']['account_id'] = "f_account";
    $schema['user_account']['account_name'] = "f_accountName";

但是在query.php中我在这一行收到错误:

$query = "select * from " . $schema['user_account']['table'] . "  where " . $schema['user_account']['user_id'] . "=:userId";

这是错误:

Notice: Undefined variable: schema in D:\Development\xampp\htdocs\account_share\php\data_access\query.php on line 8

这是项目结构(为了更容易): enter image description here

2 个答案:

答案 0 :(得分:0)

你试过像这样包括吗?

#account_page.php
$ds = DIRECTORY_SEPARATOR;
$base_dir = realpath(dirname(__FILE__)  . $ds . '..') . $ds;
$file1 = "{$base_dir}data_access{$ds}query.php"; 
$file2 = "{$base_dir}data_access{$ds}connect_to_db.php"; 
include_once($file1); 
include_once($file2);

答案 1 :(得分:0)

基于线条艺术结构......

D:\Development\xampp\htdocs\account_share\logic\account_page.php

路径

../data_access/connect_to_db.php

解析为

D:\Development\xampp\htdocs\account_share\data_access\connect_to_db.php

但你想要

D:\Development\xampp\htdocs\account_share\php\data_access\query.php

因此正确的相对路径是

../php/data_access/connect_to_db.php

但是你的截图似乎显示出一些非常不同的东西?