Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $host = 'localhost';
- $user = 'dbuser';
- $pass = 'dbpass';
- $database = NULL;
- $file = NULL;
- $table = NULL;
- $argv = $_SERVER[argv];
- if (isset($argv[1])) $database = $argv[1];
- if (isset($argv[2])) $file = $argv[2];
- if (isset($argv[3])) $table = $argv[3];
- if (is_null($database) || is_null($file)) {
- echo "Usage: $argv[0] {database} {file} {table}\n";
- exit;
- }
- if (is_null($table)) {
- $table = pathinfo($file);
- $table = $table['filename'];
- }
- echo "database: $database\n";
- echo "filename: $file\n";
- echo "tablename: $table\n";
- $db = mysql_connect($host, $user, $pass);
- mysql_select_db($database, $db);
- $q = "truncate $table";
- mysql_query($q, $db) or die(mysql_error());
- $file = $_SERVER['PWD'].'/'.$file;
- $q = "load data infile '$file' into table $table character set UTF8 fields terminated by ',' ignore 1 lines";
- mysql_query($q, $db) or die(mysql_error());
- mysql_close($db);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement