Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try {
- $mysqli = new mysqli($h, $l, $p, $b);
- if ($mysqli->connect_errno) {
- throw new Exception("Failed to connect to MySQL: " . $mysqli->connect_error);
- }
- $f_output = fopen("/media/cdrom/up", 'w');
- $strSQL = 'SHOW TABLES';
- if (!$res_tables = $mysqli->query($strSQL))
- throw new Exception("MySQL Error: " . $mysqli->error . 'SQL: '.$strSQL);
- while($row = $res_tables->fetch_array()) {
- $aTables[] = $row[0];
- }
- $res_tables->free();
- foreach($aTables as $table)
- {
- fwrite($f_output,"-- --------------------------------------------------------\n");
- fwrite($f_output,"-- Structure for '". $table."'\n");
- fwrite($f_output,"--\n\n");
- fwrite($f_output,'DROP TABLE IF EXISTS '.$table.';');
- // ask MySQL how to create the table
- $strSQL = 'SHOW CREATE TABLE '.$table;
- if (!$res_create = $mysqli->query($strSQL))
- throw new Exception("MySQL Error: " . $mysqli->error . 'SQL: '.$strSQL);
- $row_create = $res_create->fetch_assoc();
- fwrite($f_output,"\n".$row_create['Create Table'].";\n");
- fwrite($f_output,"-- --------------------------------------------------------\n");
- fwrite($f_output,'-- Dump Data for `'. $table."`\n");
- fwrite($f_output,"--\n\n");
- $res_create->free();
- $strSQL = 'SELECT * FROM '.$table;
- if (!$res_select = $mysqli->query($strSQL))
- throw new Exception("MySQL Error: " . $mysqli->error . 'SQL: '.$strSQL);
- $fields_info = $res_select->fetch_fields();
- $strFields = '';
- foreach ($fields_info as $field) {
- if ($strFields != '') $strFields .= ',';
- $strFields .= "`".$field->name."`";
- }
- fwrite($f_output,"INSERT INTO ".$table." (".$strFields.") VALUES ");
- $qinsert = "";
- $i = 0;
- while ($values = $res_select->fetch_assoc()) {
- set_time_limit(600);
- $strFields = '';
- $strValues = '';
- foreach ($fields_info as $field) {
- if ($strFields != '') $strFields .= ',';
- $strFields .= "`".$field->name."`";
- if ($strValues != '') $strValues .= ',';
- $strValues .= '"'.mysql_real_escape_string($mysqli,$values[$field->name].'"';
- }
- fwrite($f_output,"$qinsert\n(".$strValues.")");
- if($i > 290) { $qinsert = ";\nINSERT INTO ".$table." (".$strFields.") VALUES "; $i = 0; }
- else $qinsert = ", ";
- $i++;
- }
- fwrite($f_output,";\n\n\n");
- $res_select->free();
- }
- } catch (Exception $e) {
- fwrite($f_output,$e->getMessage());
- }
- fclose($f_output);
- $mysqli->close();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement