小问题,马上结贴!
http://127.0.0.1/index.php
时出现如下问题:
Fatal error: Cannot redeclare Table::MapResult() in E:\shortmessage\lib\stdTable.php on line 203
源码如下,请教原因。先谢了!
<?php
/*
数据表操作类
*/
if(!defined("__STDTABLE__"))
{
define("__STDTABLE__",1);
class Table
{
var $DBObj = NULL ;
var $TableName = '';
var $RelateTable = '';
var $RelateFields = Array();
var $PrimaryField = 'ID';
var $JoinField = 'ID';
var $UseMapMode = false;
var $MapString = ''; //格式: 映射字段名1=真实字段名1,映射字段名2=真实字段名2
var $LimitStart = 0;
var $LimitNum = 20;
var $Fields = Array();
var $Condition = "";
var $Group = '';
var $OrderField;
var $OrderType;
function Table(&$DBObj,$tableName,$Fields = '*')
{
$this->DBObj = &$DBObj;
$this->TableName = $tableName;
if($this->TableName) $this->SetFields($Fields);
}
function SetFields($Arr)
{
if(!$Arr || Trim($Arr) == '*') $this->GetFields();
else $this->Fields = $Arr;
}
function SetRelateTable($tablename)
{
$this->RelateTable = $tablename;
}
function SetRelateFields($Fields)
{
$this->RelateFields = $Fields;
}
function SetPrimaryField($FieldName)
{
$this->PrimaryField = $FieldName;
}
function SetJoinField($FieldName)
{
$this->JoinField = $FieldName;
}
function SetMapString($MapStr)
{
$this->MapString = $MapStr;
}
function SetMapMode($bool)
{
$this->UseMapMode = $bool;
}
function SetCondition($Condition)
{
$this->Condition = $Condition;
}
function SetTableName($tableName)
{
$this->TableName = $tableName;
$this->SetFields("*");
}
function CheckTableExists($tableName)
{
$result = $this->DBObj->list_tables();
for($i = 0;$i<$this->DBObj->Num_Rows($result);$i++)
if($tableName == $this->DBObj->table_name($result,$i)) return true;
return false;
}
function GetFields()
{
$rslt = $this->DBObj->List_Fields($this->TableName);
echo $this->DBObj->GetlastErrorText();
$FieldCount = $this->DBObj->Num_Fields($rslt);
$this->Fields = Array();
for($i = 0;$i < $FieldCount; $i++)
$this->Fields[] = $this->DBObj->Field_Name($rslt,$i);
}
function GetTrueField($FieldName)
{
$Arr = explode(",",$this->MapString);
for($i = 0;$i < Count($Arr); $i++)
{
if($Arr[$i][0] == $FieldName) return $Arr[$i][1];
}
return '';
}
function GetAlias($FieldName)
{
if(!$this->UseMapMode) return $FieldName;
$Arr = explode(",",$this->MapString);
for($i = 0;$i < Count($Arr); $i++)
{
if($Arr[$i][1] == $FieldName) return $Arr[$i][0];
}
return '';
}
function MapResult($Data)
{
foreach($Data as $key => $val)
{
$Data[GetTrueField($key)] = $val;
}
}
function RunSQL($SQL)
{
$err = $this->DBObj->Query($SQL);
return $err;
}
function GetFieldListString()
{
$arr = $this->Fields;
for($i = 0;$i<Count($arr);$i++)
if(trim($arr[$i])) $arr[$i] = $this->TableName . '.' . $arr[$i];
$tmpFields = implode(",",$arr);
$arr = $this->RelateFields;
for($i = 0;$i<Count($arr);$i++)
if(trim($arr[$i])) $arr[$i] = $this->RelateTable . '.' . $arr[$i];
$tmpFields1 = implode(",",$arr);
if($tmpFields1) $tmpFields = $tmpFields .",".$tmpFields1;
return $tmpFields;
}
function SetGroup($Group)
{
$this->Group = $Group;
}
function Select($Start = -1,$Num = -1,$OrderField = '', $OrderMode = ' DESC ')
{
$tmpFields = $this->GetFieldListString();
$tmpTables = $this->TableName . ($this->RelateTable ? "," . $this->RelateTable : "");
$Start = $Start == -1 ? "" : $Start;
$Num = $Num == -1 ? "" : $Num;
if($this->Condition) $tmpTerm = " where ".$this->Condition;
else $tmpTerm = ' where 1 ';
if($this->Group) $Group = "group by ".$this->Group;
if($this->RelateTable && $this->RelateFields) $tmpTerm .= " and ".$this->TableName . "." . $this->PrimaryField . " = " . $this->RelateTable . "." . $this->JoinField;
$Order = $OrderField ? " order by $OrderField $OrderMode" : "";
if($this->DBObj->DBType == DB_PLATFORM_MSSQL)
$Query = "select ".($Num ? "top $Num " : "" ).$tmpFields." from ".$tmpTables . $tmpTerm . $Group . $Order;
else
$Query = "select ".$tmpFields." from ".$tmpTables . $tmpTerm . $Group . $Order . ($Num ? " limit $Start,$Num" : "");
$this->LastResult = $this->DBObj->Query($Query);
return $this->LastResult;
}
function MapResult($rslt)
{
$List = Array();
if(!$rslt) $rslt = $this->LastResult;
while($arr = $this->DBObj->fetch_Array($rslt))
{
$List[] = $arr;
}
return $List;
}
function Insert($Arr)
{
$Fields = implode(",",$this->Fields);
if(!IS_Array($Arr)) $Arr = explode(",",$Arr);
$Values = "";
for($i = 0;$i<Count($Arr);$i++)
{
$Values .= "'".$Arr[$i]."'";
if($i < Count($Arr)-1) $Values .= ",";
}
$Query = "insert into ".$this->TableName." (".$Fields.") values(".$Values.")";
$rslt = $this->DBObj->Query($Query);
return $rslt;
}
function Update($Values)
{
$Fields = '';
if(!IS_Array($Arr)) $Arr = explode(",",$Arr);
$Count = Count($this->Fields);
for($i = 0;$i < $Count;$i++)
{
$Fields .= $this->Fields[$i] ."='".$Values[$i]."'";
if($i < $Count - 1) $Fields .= ",";
}
$Query = "update ".$this->TableName." set ".$Fields;
if($this->Condition) $Query .= " where ".$this->Condition;
$rslt = $this->DBObj->Query($Query);
return $rslt;
}
function Delete()
{
$Query = "delete from ".$this->TableName.($this->Condition ? " where ".$this->Condition : "");
return $this->DBObj->Query($Query);
}
function GetCount()
{
$tmpTables = $this->TableName . ($this->RelateTable ? "," . $this->RelateTable : "");
if($this->Condition) $tmpTerm = " where ".$this->Condition;
else $tmpTerm = ' where 1 ';
if($this->RelateTable && $this->RelateFields) $tmpTerm .= " and ".$this->TableName . "." . $this->PrimaryField . " = " . $this->RelateTable . "." . $this->JoinField;
if($this->Group) $Group = "group by ".$this->Group;
$Query = "Select Count({$this->Fields[0]}) as RowCount from ".$tmpTables." " .$tmpTerm . $Group;
$rslt = $this->DBObj->Query($Query);
$Arr = $this->DBObj->fetch_Array($rslt);
return $Arr['RowCount'];
}
}
}
?>
问题点数:20、回复次数:5Top
1 楼iasky(iasky)回复于 2006-03-24 15:32:04 得分 5
你有两个 MapResult() 方法Top
2 楼zl0126()回复于 2006-03-24 15:36:11 得分 0
这个我知道,不过两个方法的参数不一样。为什么也会出错?
该怎么改?Top
3 楼alexdream(阿辛)回复于 2006-03-24 15:54:14 得分 5
MapResult($val)
if($val==$data){
return xxx;
}
if($val==$frist){
return xxx;
}Top
4 楼xuzuning(唠叨)回复于 2006-03-24 16:22:58 得分 10
php不支持函数重栽
function MapResult($Data) {
if(is_array()) return $this->MapResult($Data);
return $this->MapResult2($Data);
}
function MapResult1($Data)
{
foreach($Data as $key => $val)
{
$Data[GetTrueField($key)] = $val;
}
}
function MapResult2($rslt)
{
$List = Array();
if(!$rslt) $rslt = $this->LastResult;
while($arr = $this->DBObj->fetch_Array($rslt))
{
$List[] = $arr;
}
return $List;
}
Top
5 楼zl0126()回复于 2006-03-24 17:07:18 得分 0
谢谢!Top




