daily pastebin goal
21%
SHARE
TWEET

Mysqli

a guest Jun 14th, 2018 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top