日期:2014-05-16  浏览次数:20431 次

怎么总是遇见这类function query(),function fetch_array()这类错误呢
/**
 * 生成数据库备份文件
 */
function sql_dumptable($table, $vol_size, $startfrom = 0, $currsize = 0)
{
global $startrow;

$allow_max_size = intval(@ ini_get('upload_max_filesize')); //单位M
if ($allow_max_size > 0 && $vol_size > ($allow_max_size * 1024))
{
$vol_size = $allow_max_size * 1024; //单位K
}

if ($vol_size > 0)
{
$vol_size = $vol_size * 1024;
}

if (!isset ($tabledump))
{
$tabledump = '';
}
$offset = 100;
if (!$startfrom)
{
$tabledump = "DROP TABLE IF EXISTS $table;\n";
$sql="SHOW CREATE TABLE ".$table."";
$createtable = $GLOBALS['zangbao']->query($sql);                        $create = $GLOBALS['zangbao']->fetch_array($createtable);
$tabledump .= $create[1] . ";\n\n";
if ($GLOBALS['zangbao']->version() > '4.1' && $this->sqlcharset)
{
$tabledump = preg_replace("/(DEFAULT)*\s*CHARSET=[a-zA-Z0-9]+/", "DEFAULT CHARSET=" . $this->sqlcharset, $tabledump);    
}
}
$tabledumped = 0;
$numrows = $offset;
while ($currsize + strlen($tabledump) < $vol_size && $numrows == $offset)
{
$tabledumped = 1;
$rows = $GLOBALS['zangbao']->query("SELECT * FROM $table LIMIT $startfrom, $offset");
$numfields = $GLOBALS['zangbao']->num_fields($rows);
$numrows = $GLOBALS['zangbao']->num_rows($rows);
while ($row = $GLOBALS['zangbao']->fetch_array($rows))
{
$comma = "";
$tabledump .= "INSERT INTO $table VALUES(";
for ($i = 0; $i < $numfields; $i++)
{
$tabledump .= $comma . "'" . $GLOBALS['zangbao']->escape_string($row[$i]) . "'";
$comma = ",";
}
$tabledump .= ");\n";
}
$startfrom += $offset;
}
$startrow = $startfrom;
$tabledump .= "\n";
return $tabledump;
}
Fatal error: Call to a member function query() on a non-object in E:\wamp\www\zangbaoshengwu\admin\include\backup.class.php on line 108
我这是做的数据库备份恢复程序,红色那行和下面的一行总是出错,我已经在类文件里面定义了的
------解决方案--------------------
print_r($GLOBALS['zangbao']); 
看看!多半不是数据库类的实例