[英]file include error in php
I am having this file structure and getting two errors: 我有此文件结构,并遇到两个错误:
php-
|
|=objects
| |=account.php
|
|=data_access
| |=connect_to_db.php
| |=query.php
| |=db_schema.php
logic-
|
|=account_page.php
First error: now in account_page.php
I am including this: 第一个错误:现在在
account_page.php
我包括以下内容:
include_once'D:\Development\xampp\htdocs\account_share\php\data_access\query.php';
include_once '../data_access/connect_to_db.php';
The full path is ok but the second gets error: Warning: include_once(../data_access/connect_to_db.php): failed to open stream: No such file or directory in D:\\Development\\xampp\\htdocs\\account_share\\php\\logic\\accounts_page.php on line 3 完整路径尚可,但第二个则出错:警告:include_once(../ data_access / connect_to_db.php):无法打开流:D:\\ Development \\ xampp \\ htdocs \\ account_share \\ php \\ logic中没有此类文件或目录\\ accounts_page.php在第3行
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
Second error: in db_schema.php
I have this array: 第二个错误:在
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";
but in query.php I am getting an error at this line: 但是在query.php中,我在此行遇到错误:
$query = "select * from " . $schema['user_account']['table'] . " where " . $schema['user_account']['user_id'] . "=:userId";
here is the error: 这是错误:
Notice: Undefined variable: schema in D:\Development\xampp\htdocs\account_share\php\data_access\query.php on line 8
Here is the project structure (to make it easier): 这是项目结构(使其变得更容易):
Have you tried to include like this? 您是否尝试过包含这样的内容?
#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);
Based on the line art structure.... 基于线条艺术结构。
In 在
D:\Development\xampp\htdocs\account_share\logic\account_page.php
The path 路径
../data_access/connect_to_db.php
resolves to 决心
D:\Development\xampp\htdocs\account_share\data_access\connect_to_db.php
but you want 但是你想要
D:\Development\xampp\htdocs\account_share\php\data_access\query.php
hence the correct relative path is 因此正确的相对路径是
../php/data_access/connect_to_db.php
But your screenshots seem to show something very different? 但是您的屏幕截图似乎显示出很大的不同?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.