/**
* 生成数据库备份文件
*/
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']);
看看!多半不是数据库类的实例
print_r($GLOBALS['zangbao']);
看看!多半不是数据库类的实例
还真是数据库类实例的问题,把类实例名给换了,这里却没有换,太粗心了
所以数据库类还是用单例模式或通过函数调用比较好
版主问下,我mysql数据是中文,但是导出的脚本里面中文成乱码了