PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Wed Jul 08, 2020 8:04 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Sun Nov 28, 2010 8:19 pm 
Offline
Forum Newbie

Joined: Sat Jan 13, 2007 1:41 am
Posts: 1
Through courtesy of I have been attempting to create a backup of a clients site.

Here is my script
Syntax: [ Download ] [ Hide ]
<?php

$db_host = "localhost";
$db_name = "client_data";
$db_user = "root";
$db_pass = "password";

mysql_connect($db_host,$db_user,$db_pass);
@mysql_select_db($db_name) or die("Unable to select database.");

function datadump ($table) {

    $result .= "# Dump of $table \n";
    $result .= "# Dump DATE : " . date("d-M-Y") ."\n\n";

    $query = mysql_query("select * from $table");
    $num_fields = @mysql_num_fields($query);
    $numrow = mysql_num_rows($query);

    for ($i =0; $i<$numrow; $i++) {
      $result .= "INSERT INTO ".$table." VALUES(";
          for($j=0; $j<$num_fields; $j++) {
          $row[$j] = addslashes($row[$j]);
          $row[$j] = ereg_replace("\n","\\n",$row[$j]);
          if (isset($row[$j])) $result .= "\"$row[$j]\"" ; else $result .= "\"\"";
          if ($j<($num_fields-1)) $result .= ",";
         }  
      $result .= ");\n";
     }
     return $result . "\n\n\n";
  }
       
$pages = datadump ("pages");
$navigation = datadump ("navigation");
$users = datadump ("users");

$content = $pages . $navigation . $users;

$file_name = "Database_Backup.sql";
Header("Content-type: application/octet-stream");
Header("Content-Disposition: attachment; filename=$file_name");
echo $content;
exit;
       
?>
 


All runs well until I view the Downloaded file - all the tables and rows have been gathered but no cell information has been recorded. Here is the result.
Syntax: [ Download ] [ Hide ]
# Dump of pages
# Dump DATE : 29-Nov-2010

INSERT INTO pages VALUES("","","","","","","","","","","","");
INSERT INTO pages VALUES("","","","","","","","","","","","");
INSERT INTO pages VALUES("","","","","","","","","","","","");
INSERT INTO pages VALUES("","","","","","","","","","","","");
INSERT INTO pages VALUES("","","","","","","","","","","","");
INSERT INTO pages VALUES("","","","","","","","","","","","");
INSERT INTO pages VALUES("","","","","","","","","","","","");
INSERT INTO pages VALUES("","","","","","","","","","","","");
INSERT INTO pages VALUES("","","","","","","","","","","","");
INSERT INTO pages VALUES("","","","","","","","","","","","");
INSERT INTO pages VALUES("","","","","","","","","","","","");
INSERT INTO pages VALUES("","","","","","","","","","","","");
INSERT INTO pages VALUES("","","","","","","","","","","","");
INSERT INTO pages VALUES("","","","","","","","","","","","");
INSERT INTO pages VALUES("","","","","","","","","","","","");
INSERT INTO pages VALUES("","","","","","","","","","","","");
INSERT INTO pages VALUES("","","","","","","","","","","","");
INSERT INTO pages VALUES("","","","","","","","","","","","");
INSERT INTO pages VALUES("","","","","","","","","","","","");
INSERT INTO pages VALUES("","","","","","","","","","","","");
INSERT INTO pages VALUES("","","","","","","","","","","","");
INSERT INTO pages VALUES("","","","","","","","","","","","");

# Dump of navigation
# Dump DATE : 29-Nov-2010

INSERT INTO navigation VALUES("","","","","");

# Dump of users
# Dump DATE : 29-Nov-2010

INSERT INTO users VALUES("","","","","","","","","","");
INSERT INTO users VALUES("","","","","","","","","","");
INSERT INTO users VALUES("","","","","","","","","","");

 


As I interpret the results all connections etc. are correct for indeed the tables called do have these numbers of records - just no cell details in backup!

Can anyone help identify what is amiss? I am a newbie here and would appreciate what may be obvious being pointed out to me.

My system is Windows 7 | Apache 2 | PHP Version 5.2.11| MySQL 5.0.51a

Thanks heaps

AceTutor


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Majestic-12 [Bot] and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group