Advertisement
Guest User

Mysqli

a guest
Jun 14th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.94 KB | None | 0 0
  1. $filepath = $this->storage_path . 'marketing_opt_out.csv';
  2.  
  3. $lookupSql = 'SELECT id FROM orderwise_subscribers WHERE orderwise_id = ?';
  4. $insertSql = 'INSERT INTO orderwise_subscribers (orderwise_id, subscribed, email, status, import_into) VALUES (?, ?, ?, ?, ?)';
  5.  
  6. $status = Subscribers::STATUS_READY_TO_IMPORT;
  7. $importInto = Subscribers::IMPORT_INTO_DM;
  8.  
  9. if($fp = fopen($filepath, "r")) {
  10.     $y = 1000;
  11.     while ($csvLine = fgetcsv($fp)) {
  12.         $handle = $mysqli->query("SELECT id FROM orderwise_subscribers WHERE orderwise_id = '" . $csvLine[1] . "'");
  13.         $result = $handle->fetch_assoc();
  14.         // No record exists
  15.         if(empty($result)) {
  16.             $mysqli->query("INSERT INTO orderwise_subscribers (orderwise_id, subscribed, email, status, import_into) VALUES ({$csvLine[1]}, 0, {$csvLine[0]}, {$status}, {$importInto})");
  17.         }
  18.         if($y % 1000 == 0) {
  19.             echo "<pre>", print_r('memory usage : ' . memory_get_usage()), "</pre>";
  20.         }
  21.         $y++;
  22.     }
  23.     fclose($fp);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement