警告:include_once(../ lib / Database.php):无法打开流:没有这样的文件或目录

时间:2017-09-20 18:55:57

标签: php html css mysql

警告:include_once(../ lib / Database.php):无法打开流:第4行的C:\ xampp \ htdocs \ project \ e-commerce \ classes \ Adminlogin.php中没有此类文件或目录< / p>

警告:include_once():在C:\ xampp \ htdocs \ project \ e-commerce中打开'../lib/Database.php'以包含(include_path ='C:\ xampp \ php \ PEAR')失败第4行\ classes \ Adminlogin.php

致命错误:第17行的C:\ xampp \ htdocs \ project \ e-commerce \ classes \ Adminlogin.php中找不到“数据库”类

我该如何解决这个问题?我的代码在这里......

<?php
include '../lib/Session.php';
Session::checkLogin();
include_once '../lib/Database.php';
include_once '../helpers/Format.php';

&GT;

<?php
/**
* Adminlogin Class
*/
class Adminlogin {
    private $db; 
    private $fm; 

    public function __construct(){
        $this->db = new Database();
        $this->fm = new Format();
    }

    public function adminLogin($adminUser,$adminPass){
        $adminUser = $this->fm->validation($adminUser);
        $adminPass = $this->fm->validation($adminPass);

        $adminUser = mysqli_real_escape_string($this->db->link, $adminUser);
        $adminPass = mysqli_real_escape_string($this->db->link, $adminPass);

        if (empty($adminUser) || empty($adminPass)) {
            $loginmsg = "Username and Password must not be empty..!!";
            return $loginmsg;
        } else {
            $query = "SELECT * FROM tbl_admin WHERE adminUser = '$adminUser' AND adminPass = '$adminPass'";
            $result = $this->db->select($query); 
            if ($result != false) {
                $value = $result->fetch_assoc();

                Session::set("adminlogin", true);
                Session::set("adminId", $value['adminId']);
                Session::set("adminName", $value['adminName']);
                Session::set("adminUser", $value['adminUser']);
                header("Location:dashbord.php");
            } else{
                $loginmsg = "Username and Password not match !!";
                return $loginmsg;
            }
        }
    }
}

&GT;

3 个答案:

答案 0 :(得分:0)

您的文件夹和文件的结构是什么? 这个

include_once '../lib/Database.php';

表示您的文件夹和文件必须是 电子商务\ \班Adminlogin.php 电子商务\ libs \ Database.php

答案 1 :(得分:0)

问题是php试图在你的include_path中找到你的类,它被设置为C:\ xampp \ php \ PEAR

您可以尝试使用此方法:

include_once $_SERVER['DOCUMENT_ROOT'] . "/lib/Session.php";
include_once $_SERVER['DOCUMENT_ROOT'] . "/lib/Database.php";
include_once $_SERVER['DOCUMENT_ROOT'] . "/helpers/Format.php";

但我发现定义全局常量更好,稍后在代码中使用它:

define('HOME_DIR', 'C:\xampp\htdocs\project\e-commerce\');

include_once HOME_DIR . "/lib/Session.php";
include_once HOME_DIR . "/lib/Database.php";
include_once HOME_DIR . "/helpers/Format.php";

当您迁移到生产环境时,您必须将HOME_DIR重新定义为服务器上的内容。

答案 2 :(得分:0)

尝试这种方法:

df.loc