PHP调用自己定义的一个数据库类时出现错误?
时间:2011-09-09
来源:互联网
<?PHP
class content{
var $conn;
public $contid;
public $subject;
public $words;
public $username;
public $face;
public $email;
public $homepage;
public $createtime;
public $upperid;
function _construct(){
$this->mysqli_connect("localhost","root","","book");
mysqli_query($this->conn,"SET NAMES gbk");
}
function _destruct(){
mysqli_close($this->conn);
}
function getinfo($id){
$sql="select * from content where contid='".$id;
$result=$this->conn->query($sql);
if($row=$result->fetch_row())
{
$this->contid=$id;
$this->subject=$row[1];
$this->words=$row[2];
$this->username=$row[3];
$this->face=$row[4];
$this->email=$row[5];
$this->homepage=$row[6];
$this->createtime=$row[7];
$this->upperid=(int)$row[8];
}
}
function getrecordcount(){
$sql="select count(*) from content";
$result=$this->conn->query($sql);
if($row=$result->fetch_row())
return (int)$row[0];
else
return 0;
}
function insert(){
$sql="insert into content (subject,words,username,face,email,homepage,createtime,upperid) values ('".$this->subject."','".$this->words."','
".$this->username."','".$this->face."','".$this->email."','".$this->homepage."','".$this->createtime."','".$this->upperid."')";
$this->conn->query($sql);
}
function delete($id){
$sql="delete from content where contid=".$id."or upperid".$id;
$this->conn->query($sql);
}
function load_content_byupperid($uid){
$sql="select * from content where upperid=".$uid."order by createtime desc";
$result=$this->conn->query($sql);
return $result;
}
function load_content_bypage($pageno,$pagesize){
$sql="select * from content order by createtime desc limit".($pageno-1)*$pagesize.",".$pagesize;
$result=$this->conn->query($sql);
return $result;
}
}
?>
然后在另一个网页使用,include调入上面这个网页时,出现了这样一个错误:Fatal error: Call to a member function query() on a non-object ,
我应该已经实例化类了呀,为什么还是不能调用呢?
作者: abc15067436552 发布时间: 2011-09-09
function _construct(){
$this->mysqli_connect("localhost","root","","book");
mysqli_query($this->conn,"SET NAMES gbk");
}
mysqli_connect有定义么,
作者: hikklong 发布时间: 2011-09-09
作者: abc15067436552 发布时间: 2011-09-09
作者: abc15067436552 发布时间: 2011-09-09
function getrecordcount(){
$sql="select count(*) from content";
$result=$this->conn->query($sql); if($row=$result->fetch_row())
return (int)$row[0];
else
return 0;
}
作者: abc15067436552 发布时间: 2011-09-09
$this->conn = mysqli_connect("localhost","root","","book");
mysqli_query($this->conn,"SET NAMES gbk");
}
作者: xuzuning 发布时间: 2011-09-09
作者: yunprince 发布时间: 2011-09-09
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28