Title: Database changes broke my interface
Last modified: March 1, 2019

---

# Database changes broke my interface

 *  [murraycollingwood](https://wordpress.org/support/users/murraycollingwood/)
 * (@murraycollingwood)
 * [7 years, 3 months ago](https://wordpress.org/support/topic/database-changes-broke-my-interface/)
 * Because you didn’t have an API I wrote my own.
    Now your database changes have
   broken my API. Can you please explain what changes I should be making to this
   code in order to be compliant with the new version?
 * It looks like the subscriber list has moved from ‘es_emaillist’ to ‘ig_contacts’–
   is that the only change I need to be concerned with?
 * Cheers
    Murray
 * My API is below (in case you want to incorporate this into a future release):
   
   <?php
 * /**
    * TO SUBSCRIBE: * [http://myurl/api.php?subsemail=my@email.com&subsname=test](http://myurl/api.php?subsemail=my@email.com&subsname=test)**
   TO CHECK: * [http://myurl/api.php?subsemail=my@email.com&subsname=test&check=1](http://myurl/api.php?subsemail=my@email.com&subsname=test&check=1)**
   TO UNSUBSCRIBE: * [http://myurl/api.php?subsemail=my@email.com&subsname=%5Bsecret%5D](http://myurl/api.php?subsemail=my@email.com&subsname=%5Bsecret%5D)*/
 * // Returns the value if the content exists and matches the regexp, else null
   
   function cleanRequest($requestName, $regexp, $bool = false) { if (!isset($_REQUEST[
   $requestName])) // REGEXP checked return null;
 *  if (filter_var($_REQUEST[$requestName], FILTER_VALIDATE_REGEXP, array(“options”
   => array(“regexp” => $regexp))) !== false)
    return $_REQUEST[$requestName]; //
   REGEXP checked
 *  if ($bool) // All we need to know is that the parameter existed
    return true;
 *  trigger_error(“REGEXP failed for _REQUEST[$requestName] (len=” . strlen($_REQUEST[
   $requestName]) . “) didn’t match $regexp”, E_USER_WARNING); // REGEXP checked
 *  return null;
    }
 * /**
    * We should have some parameters to read */ $email = cleanRequest(“subsemail”,“/
   ^\w[-\w\._]*@[-\w\._]+$/”); // Test for an email address if (!$email) { // print“
   <p>Email not found</p>”; return; }
 * $name = cleanRequest(“subsname”, “/^[^\(\);]*$/”);
    if (!$name) { // print “<
   p>Name not found</p>”; return; }
 * // Returns true if the value is 1
    $check = cleanRequest(“check”, “/^1$/”);
 * try {
    $pdo = new PDO(“mysql:host=” . DB_HOST . “;dbname=” . DB_NAME, DB_USER,
   DB_PASSWORD); // set the PDO error mode to exception $pdo->setAttribute(PDO::
   ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // print “<p>Connected successfully</p
   >”; } catch(PDOException $e) { print “<p>Connection failed: ” . $e->getMessage().“
   </p>”; }
 * /**
    * WordPress Database Table prefix. */ $table_prefix = “tzzu_”; $table_name
   = “es_emaillist”; $table = $table_prefix . $table_name;
 * // Check first if this user is already subscribed
    $stmt = $pdo->prepare(“SELECT
   1 FROM `$table` WHERE `es_email_mail` = :email”); $stmt->execute([’email’ => 
   $email]); $userCount = $stmt->fetchColumn();
 * if ($userCount) {
    // The email address already exists if ($check) { print 1;
   return; }
 *  // print “<p>FOUND: User count = $userCount</p>”;
    $parms = [secret] if ($parms&&
   isset($parms[“name”]) && $parms[“name”] == “[secret]”) { $stmt = $pdo->prepare(“
   DELETE FROM `$table` WHERE `es_email_mail` = :email”); $stmt->execute([’email’
   => $email]); }
 *  print “Unsubscribed”;
    return; } // print “<p>We didn’t find the email – so 
   now we add a record</p>”; if ($check) { print 0; return; }
 * $guid = sprintf(‘%04X%04X-%04X-%04X-%04X-%04X%04X%04X’,
    mt_rand(0, 65535), mt_rand(
   0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(
   0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
 * // print “<p>GUID = $guid</p>”;
 * // Add the user
    $stmt = $pdo->prepare(“INSERT INTO `$table`(`es_email_name`,`
   es_email_mail`, `es_email_status`, `es_email_created`, `es_email_viewcount`, `
   es_email_group`, `es_email_guid`) VALUES(:sname, :email, :stat, :created, :viewcount,:
   group, :sguid)”);
 * $stmt->execute(array(
    “sname” => $name, “email” => $email, “stat” => “Confirmed”,“
   created” => strftime(“%Y-%m-%d %H:%M:%S”, time()), “viewcount” => 0, “group” 
   => “Public”, “sguid” => $guid ));
 * // print “<p>It is done</p>”;
    print “Subscribed”; return;

The topic ‘Database changes broke my interface’ is closed to new replies.

 * ![](https://ps.w.org/email-subscribers/assets/icon-256x256.png?rev=2274172)
 * [Email Subscribers & Newsletters - Email Marketing, Post Notifications & Newsletter Plugin for WordPress](https://wordpress.org/plugins/email-subscribers/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/email-subscribers/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/email-subscribers/)
 * [Active Topics](https://wordpress.org/support/plugin/email-subscribers/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/email-subscribers/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/email-subscribers/reviews/)

 * 0 replies
 * 1 participant
 * Last activity: [7 years, 3 months ago](https://wordpress.org/support/topic/database-changes-broke-my-interface/)
 * Status: not resolved