Backup database with php

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Backup database with php

    Helo coderz, help me with a single php script to backup my database... Grateful

    #2
    Backup Your MySQL Database Using PHP

    Comment


      #3
      Thanx, but did n0t w0rkz...

      Comment


        #4
        try to backup via cpanel.. its very easy.. keep copy of ur db on ur local machine..

        Comment


          #5
          @Pyramid, when i backup frm cpanel the c0ntent iz n0t of my database. But html c0ntents. Iz n0t w0rking fr0m my cpanel.

          Comment


            #6
            Originally posted by Wintch View Post
            @Pyramid, when i backup frm cpanel the c0ntent iz n0t of my database. But html c0ntents. Iz n0t w0rking fr0m my cpanel.
            if u r using dedicated server than i can help u on this for sure.... leave ur reply

            Comment


              #7
              Login To PMA >Select Ur DB >click On Export

              Comment


                #8
                @Pyramid am using xtreemh0zt, iz it dedicated server?

                Comment


                  #9
                  dude, search tool... here you go, posted this a while back... (don't forget to click thanks, lol)

                  C3 Themes: http://c3themes.wen.ru/index.html
                  Find Files: http://mystarter.tk/?goto=X-search

                  Comment


                    #10
                    i used this before one year ago..........

                    Originally posted by Wintch View Post
                    Helo coderz, help me with a single php script to backup my database... Grateful

                    PHP Code:
                    backup_tables('localhost','username','password','blog');


                    /* backup the db OR just a table */
                    function backup_tables($host,$user,$pass,$name,$tables '*')
                    {
                      
                      
                    $link mysql_connect($host,$user,$pass);
                      
                    mysql_select_db($name,$link);
                      
                      
                    //get all of the tables
                      
                    if($tables == '*')
                      {
                        
                    $tables = array();
                        
                    $result mysql_query('SHOW TABLES');
                        while(
                    $row mysql_fetch_row($result))
                        {
                          
                    $tables[] = $row[0];
                        }
                      }
                      else
                      {
                        
                    $tables is_array($tables) ? $tables explode(',',$tables);
                      }
                      
                      
                    //cycle through
                      
                    foreach($tables as $table)
                      {
                        
                    $result mysql_query('SELECT * FROM '.$table);
                        
                    $num_fields mysql_num_fields($result);
                        
                        
                    $return.= 'DROP TABLE '.$table.';';
                        
                    $row2 mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table));
                        
                    $return.= "\n\n".$row2[1].";\n\n";
                        
                        for (
                    $i 0$i $num_fields$i++) 
                        {
                          while(
                    $row mysql_fetch_row($result))
                          {
                            
                    $return.= '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])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
                              if (
                    $j<($num_fields-1)) { $return.= ','; }
                            }
                            
                    $return.= ");\n";
                          }
                        }
                        
                    $return.="\n\n\n";
                      }
                      
                      
                    //save file
                      
                    $handle fopen('db-backup-'.time().'-'.(md5(implode(',',$tables))).'.sql','w+');
                      
                    fwrite($handle,$return);
                      
                    fclose($handle);


                    you must hide this from other users....................................
                    otherwise .................................................. .
                    Last edited by Dj_ThimirA; 15.03.12, 09:10.

                    Comment

                    Working...
                    X