请帮帮我
致命错误:在第104行的/home/u357965800/public_html/include/class.admin.php中调用非对象的成员函数prepare()
<?php
include_once('class.database.php');
class ManageAdmins
{
public $link;
function __construct()
{
global $prefix;
$db_connection = new dbConnection();
$this->link = $db_connection->connect();
return $this->link;
}
function AddAdmin($ausername,$apass,$afname,$alname,$aemail,$atel,$apic,$allow_term_add, $allow_term_list, $allow_term_edit, $allow_term_del, $allow_class_add, $allow_class_list, $allow_class_edit, $allow_class_del, $allow_lesson_add, $allow_lesson_list, $allow_lesson_edit, $allow_lesson_del, $allow_teacher_add, $allow_teacher_list, $allow_teacher_edit, $allow_teacher_del, $allow_course_add, $allow_course_list, $allow_course_edit, $allow_course_del, $allow_student_add, $allow_student_list, $allow_student_edit, $allow_student_del, $allow_cs_add, $allow_cs_list, $allow_cs_edit, $allow_cs_del, $allow_score_add, $allow_score_list, $allow_score_edit, $allow_chair_manage, $allow_admins_add, $allow_admins_list, $allow_admins_edit, $allow_admins_del, $allow_settings, $allow_homepage_message, $acomment, $admin_id)
{
global $prefix;
$query = $this->link->prepare("INSERT INTO `".$prefix."admins` (`ausername`, `apass`, `afname`, `alname`, `aemail`, `atel`, `apic`, `allow_term_add`, `allow_term_list`, `allow_term_edit`, `allow_term_del`, `allow_class_add`, `allow_class_list`, `allow_class_edit`, `allow_class_del`, `allow_lesson_add`, `allow_lesson_list`, `allow_lesson_edit`, `allow_lesson_del`, `allow_teacher_add`, `allow_teacher_list`, `allow_teacher_edit`, `allow_teacher_del`, `allow_course_add`, `allow_course_list`, `allow_course_edit`, `allow_course_del`, `allow_student_add`, `allow_student_list`, `allow_student_edit`, `allow_student_del`, `allow_cs_add`, `allow_cs_list`, `allow_cs_edit`, `allow_cs_del`, `allow_score_add`, `allow_score_list`, `allow_score_edit`, `allow_chair_manage`, `allow_admins_add`, `allow_admins_list`, `allow_admins_edit`, `allow_admins_del`, `allow_settings`, `allow_homepage_message`, `acomment`, `admin_id`)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
");
$values = array($ausername,$apass,$afname,$alname,$aemail,$atel,$apic,$allow_term_add, $allow_term_list, $allow_term_edit, $allow_term_del, $allow_class_add, $allow_class_list, $allow_class_edit, $allow_class_del, $allow_lesson_add, $allow_lesson_list, $allow_lesson_edit, $allow_lesson_del, $allow_teacher_add, $allow_teacher_list, $allow_teacher_edit, $allow_teacher_del, $allow_course_add, $allow_course_list, $allow_course_edit, $allow_course_del, $allow_student_add, $allow_student_list, $allow_student_edit, $allow_student_del, $allow_cs_add, $allow_cs_list, $allow_cs_edit, $allow_cs_del, $allow_score_add, $allow_score_list, $allow_score_edit, $allow_chair_manage, $allow_admins_add, $allow_admins_list, $allow_admins_edit, $allow_admins_del, $allow_settings, $allow_homepage_message, $acomment, $admin_id);
for($i=7;$i<45;$i++)
if(empty($values[$i]))
$values[$i]=0;
$query->execute($values);
$counts = $query->rowCount();
return $counts;
}
function UpdateAdmin($aid,$ausername,$afname,$alname,$aemail,$atel,$apic,$allow_term_add, $allow_term_list, $allow_term_edit, $allow_term_del, $allow_class_add, $allow_class_list, $allow_class_edit, $allow_class_del, $allow_lesson_add, $allow_lesson_list, $allow_lesson_edit, $allow_lesson_del, $allow_teacher_add, $allow_teacher_list, $allow_teacher_edit, $allow_teacher_del, $allow_course_add, $allow_course_list, $allow_course_edit, $allow_course_del, $allow_student_add, $allow_student_list, $allow_student_edit, $allow_student_del, $allow_cs_add, $allow_cs_list, $allow_cs_edit, $allow_cs_del, $allow_score_add, $allow_score_list, $allow_score_edit, $allow_chair_manage, $allow_admins_add, $allow_admins_list, $allow_admins_edit, $allow_admins_del, $allow_settings, $allow_homepage_message, $acomment, $admin_id)
{
global $prefix;
$query = $this->link->prepare("UPDATE `".$prefix."admins` SET `ausername`=?, `afname`=?, `alname`=?, `aemail`=?, `atel`=?, `apic`=?, `allow_term_add`=?, `allow_term_list`=?, `allow_term_edit`=?, `allow_term_del`=?, `allow_class_add`=?, `allow_class_list`=?, `allow_class_edit`=?, `allow_class_del`=?, `allow_lesson_add`=?, `allow_lesson_list`=?, `allow_lesson_edit`=?, `allow_lesson_del`=?, `allow_teacher_add`=?, `allow_teacher_list`=?, `allow_teacher_edit`=?, `allow_teacher_del`=?, `allow_course_add`=?, `allow_course_list`=?, `allow_course_edit`=?, `allow_course_del`=?, `allow_student_add`=?, `allow_student_list`=?, `allow_student_edit`=?, `allow_student_del`=?, `allow_cs_add`=?, `allow_cs_list`=?, `allow_cs_edit`=?, `allow_cs_del`=?, `allow_score_add`=?, `allow_score_list`=?, `allow_score_edit`=?, `allow_chair_manage`=?,`allow_admins_add`=?, `allow_admins_list`=?, `allow_admins_edit`=?, `allow_admins_del`=?, `allow_settings`=?, `allow_homepage_message`=?, `acomment`=?, `admin_id`=? WHERE `aid`=?
");
$values = array($ausername,$afname,$alname,$aemail,$atel,$apic,$allow_term_add, $allow_term_list, $allow_term_edit, $allow_term_del, $allow_class_add, $allow_class_list, $allow_class_edit, $allow_class_del, $allow_lesson_add, $allow_lesson_list, $allow_lesson_edit, $allow_lesson_del, $allow_teacher_add, $allow_teacher_list, $allow_teacher_edit, $allow_teacher_del, $allow_course_add, $allow_course_list, $allow_course_edit, $allow_course_del, $allow_student_add, $allow_student_list, $allow_student_edit, $allow_student_del, $allow_cs_add, $allow_cs_list, $allow_cs_edit, $allow_cs_del, $allow_score_add, $allow_score_list, $allow_score_edit, $allow_chair_manage, $allow_admins_add, $allow_admins_list, $allow_admins_edit, $allow_admins_del, $allow_settings, $allow_homepage_message, $acomment, $admin_id,$aid);
for($i=6;$i<44;$i++)
if(empty($values[$i]))
$values[$i]=0;
$query->execute($values);
$counts = $query->rowCount();
return $counts;
}
function ResetPassword($aid,$apass)
{
global $prefix;
$apass = md5($apass);
$query = $this->link->prepare("UPDATE `".$prefix."admins` SET `apass`=? WHERE `aid`=?");
$values = array($apass,$aid);
$query->execute($values);
$counts = $query->rowCount();
return $counts;
}
function ChangePassword($aid,$current_pass,$new_pass)
{
global $prefix;
$current_pass = md5($current_pass);
$new_pass = md5($new_pass);
$query = $this->link->prepare("SELECT * FROM `".$prefix."admins` WHERE `aid`=? AND `apass`=?");
$values = array($aid,$current_pass);
$query->execute($values);
$counts = $query->rowCount();
if($counts==1)
{
$query = $this->link->prepare("UPDATE `".$prefix."admins` SET `apass`=? WHERE aid=?");
$values = array($new_pass,$aid);
$query->execute($values);
$counts = $query->rowCount();
if($counts==1)
return 2;
else
return 3;
}
else
return 1;
}
function LoginAdmin($username,$password)
{
global $prefix;
$query = $this->link->prepare("SELECT * FROM `".$prefix."admins` WHERE ausername=? AND apass=?");
$values = array($username,$password);
$query->execute($values);
$counts = $query->rowCount();
return $counts;
}
function GetAdminInfo($username)
{
global $prefix;
$query = $this->link->prepare("SELECT * FROM `".$prefix."admins` WHERE `ausername`=?");
$values = array($username);
$query->execute($values);
$counts = $query->rowCount();
if($counts==1)
{
$result = $query->fetchAll();
return $result;
}
else
{
return $counts;
}
}
function GetAdminInfoById($aid)
{
global $prefix;
$query = $this->link->prepare("SELECT * FROM `".$prefix."admins` WHERE `aid`=?");
$values = array($aid);
$query->execute($values);
$counts = $query->rowCount();
if($counts==1)
{
$result = $query->fetchAll();
return $result;
}
else
{
return $counts;
}
}
function GetAdminList($query)
{
global $prefix;
$query = $this->link->query("SELECT * FROM `".$prefix."admins` $query ORDER BY `aid` DESC");
$counts = $query->rowCount();
if($counts>=1)
{
$result = $query->fetchAll();
return $result;
}
else
{
return $counts;
}
}
function GetAdminList2($query,$start,$limit)
{
global $prefix;
$query = $this->link->query("SELECT * FROM `".$prefix."admins` $query ORDER BY `aid` DESC LIMIT $start,$limit");
$counts = $query->rowCount();
if($counts>=1)
{
$result = $query->fetchAll();
return $result;
}
else
{
return $counts;
}
}
function UsernameAvailability($username)
{
global $prefix;
if(preg_match('/^[a-z\d_]{1,50}$/i', $username))
{
$query = $this->link->prepare("SELECT * FROM `".$prefix."admins` WHERE `ausername`=?");
$values = array($username);
$query->execute($values);
$counts = $query->rowCount();
if($counts==1)
return 0;
else
return 1;
}
else
{
return 2;
}
}
function AdminPermission($username,$module)
{
global $prefix;
$query = $this->link->prepare("SELECT * FROM `".$prefix."admins` WHERE `ausername`=? AND $module=1");
$values = array($username);
$query->execute($values);
$counts = $query->rowCount();
if($counts==1)
return 1;
else
return $counts;
}
function DeleteAdmin($aid)
{
global $prefix;
$query = $this->link->prepare("DELETE FROM `".$prefix."admins` WHERE `aid`=?");
$values = array($aid);
$query->execute($values);
$counts = $query->rowCount();
if($counts==1)
return 1;
else
return $counts;
}
function DelPic($id)
{
global $prefix;
global $pic_prefix;
$adminInfo = $this->GetAdminInfoById($id);
if(file_exists('../img/admins/'.$pic_prefix.$adminInfo[0]['aid'].$adminInfo[0]['apic']))
{
if(unlink('../img/admins/'.$pic_prefix.$adminInfo[0]['aid'].$adminInfo[0]['apic']))
return 1;
else
return 0;
}
else
return 1;
}
function LastAdminID()
{
global $prefix;
$query = $this->link->query("SELECT `aid` FROM `".$prefix."admins` ORDER BY `aid` DESC LIMIT 0,1");
$result = $query->fetchAll();
return $result[0]['aid'];
}
}
?>
答案 0 :(得分:0)
在第104行,您在prepare
上致电$this->link
:
$query = $this->link->prepare("SELECT * FROM `".$prefix."admins` WHERE `ausername`=?");
$this->link
在第11行设置:
$db_connection = new dbConnection();
$db->link = $db_connection->connect();
由于$this->link
不是对象(很可能是NULL左右),因此必须修复$db_connection->connect()
,以便它返回一个具有prepare
函数的对象。