本人初学,正在尝试自己做一个论坛,很多地方不懂,这是我定义的数据库类:
<?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 ,
我应该已经实例化类了呀,为什么还是不能调用呢?
<?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 ,
我应该已经实例化类了呀,为什么还是不能调用呢?
解决方案 »
- 这句mysql语句怎么排先后呀?
- 【php】性能问题
- PHP里面怎么用try……catch
- 请教一下,PHP都有哪几种跳转页面的方法
- 关于Smarty模板文件里相对路径的问题
- 好多php论坛源码都有这连个版本UTF-8和GBK,这两个有什么区别阿???
- select sum(test2.c3) from test2 where test2.c4=test.c2这句SQL有错吗?
- 读出数据库的数据生成一个EXCEL文件存于服务器上
- 关于php在pws上配置的问题,请高手赐教,不胜感谢!
- .htaccess中/v/U90418Y3FCJUD389\?toPage=32396跳转成 /v/U90418Y3FCJUD389/
- 网站检查发现死链和网页PR的问题
- Rewrite 问题
function _construct(){
$this->mysqli_connect("localhost","root","","book");
mysqli_query($this->conn,"SET NAMES gbk");
}mysqli_connect有定义么,
function getrecordcount(){
$sql="select count(*) from content";
$result=$this->conn->query($sql); if($row=$result->fetch_row())
return (int)$row[0];
else
return 0;
}
$this->conn = mysqli_connect("localhost","root","","book");
mysqli_query($this->conn,"SET NAMES gbk");
}