具有要求/包含的文件夹的体系结构


Architecture of folders with require/include

我有问题,我构建自己的CMS,我使用目录

主目录 - 索引.php -/模数 -/功能

/功能

  • 数据库级.php
/

模数/画廊

    /
  • 功能/画廊级.php

当我离开文件夹画廊时,它向我展示了Fatal error: Call to a member function select() on null in D:'xampp'htdocs'imcm'admin'moduls'galerie'functions'galerie-class.php on line 98

数据库级.php看起来像

    <?php
if(!class_exists("DB")){
    class DB{
        public function __construct(){
            $mysqli = new mysqli("localhost", "root", "", "imcm");
            if($mysqli->connect_errno)
            {
                printf("Připojení selhalo %s'n",$mysqli->connect_error());
                exit();
            }
            $this->connection = $mysqli;
        }

        public function insert($query){
            $result = $this->connection->query($query);
            return $this->connection->insert_id;
        }
        public function update($query)
        {
            $result = $this->connection->query($query);
        }
        public function select($query){
            $result = $this->connection->query($query);
            while($obj = $result->fetch_object()){
                    $results[] = $obj;
            }
            return $results;
        }
        public function delete($query){
            $result = $this->connection->query($query);
        }
    }
}

$db = new DB;

?>

和画廊级.php

   <?php
if(!file_exists("../../functions/db-class.php"))
{
    require_once("functions/db-class.php"); 
}
else
{
    require_once("../../functions/db-class.php");
}

if(!class_exists("GALERIE"))
{
    class GALERIE{
        function newGallery($galerie, $popis){
            global $db;
            if($galerie == ""){
                return "Pole nemůže být prázdné.";
            }
            else{
                $query = "INSERT into galerie values(null,'".$galerie."','".$popis."', '".Time()."')";
                return $db->insert($query);
            }
        }

        function updateTitle($id, $title){
            global $db;
            $query = "UPDATE fotky set title='".$title."' where id='".$id."'";
            return $db->update($query);
        }
        function deleteImage($id)
        {
            global $db;
            $query = "DELETE from fotky where id='".$id."'";
            return $db->delete($query);
        }
        function uploadImage($soubor, $id, $maxWidth, $maxHeight){
            global $db;
            $imagesize = getimagesize($soubor);
            switch($imagesize[2]){
                case 1 : $img = imagecreatefromgif($soubor); break;
                case 2 : $img = imagecreatefromjpeg($soubor); break;
                case 3 : $img = imagecreatefrompng($soubor); break;
                default : $img = imagecreatefromjpeg($soubor); break;
            }

            $height = $maxHeight;
            $width = $maxWidth;
            $width = round($imagesize[0] * $width / $imagesize[0]);
            $height = round($imagesize[1] * $height / $imagesize[1]);
            $img2 = imagecreatetruecolor($width, $height);
            imagecopyresampled($img2, $img, 0, 0, 0, 0, $width, $height, $imagesize[0], $imagesize[1]);
            $query = "INSERT into fotky values(null, '".$id."', '', '', '".Time()."')";
            $imageId = $db->insert($query);
            $query = "UPDATE fotky set name='".$id."_".$imageId.".jpg' where id='".$imageId."'";
            $db->update($query);
            imagejpeg($img2, "miniatury/".$id."_".$imageId.".jpg", 100);

            move_uploaded_file($soubor, "original/".$id."_".$imageId.".jpg");
        }

        function showFotky($idGalerie){
            global $db;
            $query = "SELECT * from fotky where gal_id='$idGalerie' order by id DESC";
            return $db->select($query);
        }
    function showGalleries(){
            global $db;

            $query = "SELECT * from galerie order by id DESC";
            return $db->select($query); //line 98
        }


    }
}



?>

感谢您的任何回复!

仅在 db-class 中定义全局$db.php