Php batch delete mySQL database records
- # Usage: php mysql_rmByKey.php
- # Usage: php mysql_rmByKey.php
- # Count ($ argv)> 0, the first $ argv [0] is the php file
- If (count ($ argv) = 7 ){
- $ User = $ argv [1];
- $ Passwd = $ argv [2];
- $ Db = $ argv [3];
- $ Table = $ argv [4];
- $ Key = $ argv [5];
- $ DelFile = $ argv [6];
- } Else if (count ($ argv) = 5 ){
- $ User = 'user ';
- $ Passwd = '000000 ';
- $ Db = $ argv [1];
- $ Table = $ argv [2];
- $ Key = $ argv [3];
- $ DelFile = $ argv [4];
- } Else {
- # Usage ();
- Echo'
- Usage: php mysql_rmByKey.php '. "\ N ";
- }
- $ Link = mysql_connect ('localhost', $ user, $ passwd );
- If (! $ Link ){
- Die ("cocould not connect to mysql server:". mysql_error ());
- }
- Mysql_select_db ($ db, $ link );
- $ Fp = fopen ($ delFile, 'r ');
- While (! Feof ($ fp) & $ ln = fgets ($ fp )){
- $ Id = chop ($ ln );
- $ SQL = "delete from $ table where $ key = '$ ID ';";
- Mysql_query ($ SQL, $ link );
- }
- Fclose ($ fp );
- Mysql_close ($ link );
- ?>
|