Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. <?php
  2. $host = 'localhost';
  3. $user = 'dbuser';
  4. $pass = 'dbpass';
  5.  
  6. $database = NULL;
  7. $file = NULL;
  8. $table = NULL;
  9.  
  10. $argv = $_SERVER[argv];
  11. if (isset($argv[1])) $database = $argv[1];
  12. if (isset($argv[2])) $file = $argv[2];
  13. if (isset($argv[3])) $table = $argv[3];
  14.  
  15. if (is_null($database) || is_null($file)) {
  16. echo "Usage: $argv[0] {database} {file} {table}\n";
  17. exit;
  18. }
  19.  
  20. if (is_null($table)) {
  21. $table = pathinfo($file);
  22. $table = $table['filename'];
  23. }
  24.  
  25. echo "database: $database\n";
  26. echo "filename: $file\n";
  27. echo "tablename: $table\n";
  28.  
  29. $db = mysql_connect($host, $user, $pass);
  30. mysql_select_db($database, $db);
  31.  
  32. $q = "truncate $table";
  33. mysql_query($q, $db) or die(mysql_error());
  34.  
  35. $file = $_SERVER['PWD'].'/'.$file;
  36. $q = "load data infile '$file' into table $table character set UTF8 fields terminated by ',' ignore 1 lines";
  37. mysql_query($q, $db) or die(mysql_error());
  38. mysql_close($db);
  39. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement