我有问题,我建立自己的CMS,我使用目录
主目录 - index.php - / moduls - / functions
/功能
/ moduls /涉
当我访问文件夹galerie时,它显示了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
db-class.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;
?>
和galerie-class.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
}
}
}
?>
感谢您的回复!
答案 0 :(得分:0)
仅在db-class.php中定义全局$ db