首页 新闻 会员 周边

问下我的代码哪错了->Fatal error: Call to a member function query() on a non-object

0
悬赏园豆:15 [已关闭问题] 关闭于 2011-02-20 10:18

如何代码没错
article.class.php已经继承了BaseLogic和MyDB


错误提示:Fatal error: Call to a member function query() on a non-object in G:\www\oldway\class\BaseLogic.class.php on line 40

 
add.php

<?php
header("Content-Type:text/html; charset=utf-8");
require_once("../../config.inc.php");
function __autoload($file){
require_once "../../class/".$file.".class.php";
}
$article=new article();
if(isset($_POST['button'])){
$addArticle=$article->addArticle($_POST);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>添加</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="#">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td></td><td><?php echo @$article->getMessList()?></td></tr>
<tr>
<td width="20%">标题</td>
<td width="80%">
<input type="text" name="title" id="title" /></td>
</tr>
<tr>
<td>作者</td>
<td>
<input type="text" name="author" id="author" /></td>
</tr>
<tr>
<td>内容</td>
<td>
<textarea name="content" id="content" cols="45" rows="5"></textarea></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="button" id="button" value="提交" /></td>
</tr>
</table>
</form>
</body>
</html>

 


Article.class.php
class Article extends BaseLogic{
function __construct(){
$this->tabName = TAB_PREFIX."article";
$this->fieldList = array("cid","title","author","content","tages","posttime");
}

function addArticle($post=""){
$_POST["content"]=stripslashes($_POST['content']);
if($this->add($post)){
$this->messList[]="添加成功!";
return true;
}
else{
$this->messList[]="添加成功";
return true;
}
}
}

 


BaseLogic.class.php
class BaseLogic extends MyDB{
protected $tabName;
protected $messList;
protected $fieldList;

function add($postlist){
$fieldList='';
$value='';

foreach($postlist as $k=>$v){
if(in_array($k,$this->fieldList)){
$fieldList.=$k.",";
if(get_magic_quotes_gpc()){
$value .= "'".$v."',";
}
else{
$value .= "'".addslashes($v)."',";
}
}

}
$fieldList = rtrim($fieldList,",");
$value = rtrim($value,",");

$sql = "insert info {$this->tabName} (".$fieldList.") values (".$value.")";
$result=$this->mysqli->query($sql);

if($result && $this->mysqli->affected_rows >0){
return $this->mysql->insert_id;
}
else{
return false;
}
}

public function getMessList(){
if(!empty($this->messList)){
foreach($this->messList as $v){
$message .= "<font color=red>".$v."</font><br>";
}
}
return $message;
}
}

 


MyDB.class.php
class MyDB{
protected $mysqli;
protected $showerror;
function __construct($showerror=true){
$this->showerror = $showerror;
$this->mysqli = new MySQLi(DB_HOST,DB_USER,DB_PWD,DB_NAME);
if(mysqli_connect_errno()){
echo $this->printerror("链接数据库错误 ".mysqli_connect_error());
$this->mysqli=false;
exit();
}
$this->mysqli->query("set names '{APP_CODE}'");
}
protected function printerror($errormessage=""){
if($this->showerror){
if($errormessage==""){
$errormessage=$this->mysqli->errno.":".$this->mysqli->error;
echo "<p><b>MySql 错误:</b>".htmlspecialchars($errormessage)."</p>";
}
else{
echo "<p><font color=red>".htmlspecialchars($errormessage)."</font></p>";
}
exit();
}
}

public function close(){
if($this->mysqli){
$this->mysqli->close();
}
else{
$this->mysqli=false;
}
}

function __destruct(){
$this->close();
}
}

 



config.inc.php
define("DB_HOST","127.0.0.1"); 
 define("DB_USER","root"); 
 define("DB_PWD",""); 
 define("DB_NAME","dome"); 
 define("TAB_PREFIX","td_");  
define("APP_CODE","UTF8");

 



順唭洎嘫的主页 順唭洎嘫 | 初学一级 | 园豆:114
提问于:2011-02-18 10:35
< >
分享
所有回答(1)
0

1. 数据库类MySQLi里好像少了个query函数

public function query($s){

return mysql_query($s);

}

或者

在add方法前 加个public试试

 

初学者 仅供参考!

lorry01 | 园豆:105 (初学一级) | 2011-02-18 23:36
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册