Advertisement
Virajsinh

MySQL Database Server Backup And Restore Using PhP

Nov 13th, 2021 (edited)
1,232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.92 KB | None | 0 0
  1. <?php
  2.     //Reference => https://github.com/gocom/danpu Or https://github.com/ifsnop/mysqldump-php
  3.    
  4.     //Export Code
  5.     use Rah\Danpu\Dump;
  6.     use Rah\Danpu\Export;
  7.    
  8.     try {
  9.         $dump = new Dump;
  10.         $dump
  11.             ->file('/path/to/imported/file.sql')
  12.             ->dsn('mysql:dbname=database;host=localhost')
  13.             ->user('username')
  14.             ->pass('password')
  15.             ->tmp('/tmp');
  16.  
  17.         new Export($dump);
  18.     } catch (\Exception $e) {
  19.         echo 'Export failed with message: ' . $e->getMessage();
  20.     }
  21.  
  22.     // Import Code
  23.     use Rah\Danpu\Dump;
  24.     use Rah\Danpu\Import;
  25.     try {
  26.         $dump = new Dump;
  27.         $dump
  28.             ->file('/path/to/imported/file.sql')
  29.             ->dsn('mysql:dbname=database;host=localhost')
  30.             ->user('username')
  31.             ->pass('password')
  32.             ->tmp('/tmp');
  33.  
  34.         new Import($dump);
  35.     } catch (\Exception $e) {
  36.         echo 'Import failed with message: ' . $e->getMessage();
  37.     }
  38.  
  39.    
  40. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement