How can I always encounter errors such as functionquery () and functionfetch_array /**
* Generate database backup files
*/
Function SQL _dumptable ($ table, $ vol_size, $ startfrom = 0, $ currsize = 0)
{
Global $ startrow;
$ Allow_max_size = intval (@ ini_get ('upload _ max_filesize '); // unit: M
If ($ allow_max_size> 0 & $ vol_size> ($ allow_max_size * 1024 ))
{
$ Vol_size = $ allow_max_size * 1024; // unit: 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 ";
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
I am a database backup and recovery program. there is always an error in the red line and the following line. I have defined it in the class file.
Reply to discussion (solution)
Print_r ($ GLOBALS ['zangbao']);
Look! Most of them are not database instances.
Print_r ($ GLOBALS ['zangbao']);
Look! Most of them are not database instances.
It was really a problem with database-class instances. I changed the class instance name but it was not changed here, so careless.
Therefore, it is better to use the Singleton mode or function call for database classes.
The moderator asked me if mysql data is Chinese, but the exported scripts contain garbled characters.