0) { $l = mysql_fetch_row($r); $sqldump .= $l[1]; if (preg_match("/auto_increment/s",$l[1])) { mysql_free_result($r); $q = 'SHOW TABLE STATUS LIKE "' . $table . '"'; $r = ocsql_query($q) or backuperr("Unable to query auto increment value for $table $q"); $l = mysql_fetch_array($r); $sqldump .= " AUTO_INCREMENT=" . $l['Auto_increment']; } $sqldump .= ";\n\n\n"; } mysql_free_result($r); $q = 'SELECT * FROM ' . quoteit($table); $r = ocsql_query($q) or backuperr("Unable to query table contents for $table"); $fieldNum = mysql_num_fields($r); $recNum = mysql_num_rows($r); $sqldump .= ' # # Records in table ' . quoteit($table) . ' (' . $recNum . ') # '; $fieldAR = array(); for ($f=0; $f < $fieldNum; $f++) { $fieldAR[$f] = quoteit(mysql_field_name($r,$f)); if (preg_match("/(?:int|timestamp)$/",mysql_field_type($r,$f))) { $fieldNumAR[$f] = TRUE; } else { $fieldNumAR[$f] = FALSE; } } $fldVal = array(); while ($row = mysql_fetch_row($r)) { $sqldump .= 'INSERT INTO ' . quoteit($table) . ' VALUES ('; for ($f=0; $f < $fieldNum; $f++) { if (!isset($row[$f])) { $fldVal[] = 'NULL'; } elseif (($row[$f] == '0') || ($row[$f] != '')) { if ($fieldNumAR[$f]) { $fldVal[] = $row[$f]; } else { $fldVal[] = "'" . safeSQLstr($row[$f]) . "'"; } } else { $fldVal[] = "''"; } } $sqldump .= implode(', ', $fldVal) . ");\n"; unset($fldVal); } mysql_free_result($r); } // for tables $fileName = 'openconf'; if (preg_match("/^\w+$/", $OC_configAR['OC_confName'])) { $fileName .= '-' . $OC_configAR['OC_confName']; } $fileName .= '-' . date('YmdHi') . '.sql'; oc_sendNoCacheHeaders(); header('Content-Type: text/plain'); header('Content-Disposition: attachment; filename="' . $fileName . '"'); print $sqldump; ?>