function data2sql($table) { global $db; $tabledump = table2sql($table); $rows = $db->query("SELECT * FROM {$table}"); $nums = $db->affected_rows(); $numfields = $db->num_fields(); while ($row = mysql_fetch_row($rows)) { $comma = ""; $tabledump .= "INSERT INTO {$table} VALUES("; for ($i = 0; $i < $numfields; $i++) { $tabledump .= $comma . "'" . mysql_escape_string($row[$i]) . "'"; $comma = ","; } $tabledump .= ");\n"; } $tabledump .= "\n"; return $tabledump; }
/** * 备份数据库 * * @param resource $con 数据库连接 * @param string $dbname 数据库名 * @return string $dumpSql 数据库SQL */ function backupDB($con, $dbname, $dbprefix) { mysql_query('USE ' . $dbname, $con); $result = mysql_query('SHOW TABLES', $con); $version = getVersion($con, $dbname, $dbprefix); $dumpSql = t('bugfree', 'BugFree backup header {version}', array('{version}' => $version)); while ($row = mysql_fetch_array($result)) { $dumpSql .= table2sql($con, $row[0]); } return $dumpSql; }