Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to take backup of a table in MySQL using PHP?

    • 0
    • 1
    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 122
    Comment on it

    You can use PHP to take backup of a table in MySQL. For this, you need to write the following code:

       $dbhost = 'localhost';
       $dbuser = 'dbusername';
       $dbpass = 'dbpassword';
    
       $conn = mysql_connect($dbhost, $dbuser, $dbpass);
    
       if(! $conn )
       {
          die('Could not connect: ' . mysql_error());
       }
    
       $table_name = "tablename";
       $backup_file  = "/var/tmp/tablebck.sql";
       $sql = "SELECT * INTO OUTFILE '$backup_file' FROM $table_name";
    
       mysql_select_db('tablename');
       $retval = mysql_query( $sql, $conn );
    
       if(! $retval )
       {
          die('Could not take data backup: ' . mysql_error());
       }
    
       echo "Backedup  data successfully\n";
    
       mysql_close($conn);
    
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: