daily pastebin goal
85%
SHARE
TWEET

mysqli prepared statements

a guest Jun 14th, 2018 69 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. $status = Subscribers::STATUS_READY_TO_IMPORT;
  4. $importInto = Subscribers::IMPORT_INTO_DM;
  5.  
  6. $lookupStmt = $mysqli->prepare("SELECT id FROM orderwise_subscribers WHERE orderwise_id = ?");
  7. $insertStmt = $mysqli->prepare("INSERT INTO orderwise_subscribers (
  8.     orderwise_id, subscribed, email, status, import_into
  9. ) VALUES (
  10. ?, 0, ?, 1, 1)");
  11.  
  12. if($fp = fopen($filepath, "r")) {
  13.     $y = 1000;
  14.     while ($csvLine = fgetcsv($fp)) {
  15.         $lookupStmt->bind_param('s', $csvLine[1]);
  16.         $lookupStmt->execute();
  17.         $result = $lookupStmt->get_result();
  18.         // // No record exists
  19.         if($result->num_rows === 0) {
  20.             $insertStmt->bind_param('ss', $csvLine[1], $csvLine[0]);
  21.             $insertStmt->execute();
  22.         }
  23.         if($y % 1000 == 0) {
  24.             echo "<pre>", print_r('memory usage : ' . memory_get_usage()), "</pre>";
  25.         }
  26.         $y++;
  27.     }
  28.     fclose($fp);
  29. }
  30. $lookupStmt->close();
  31. $insertStmt->close();
  32. $mysqli->close();
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