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
MurrayMy API is below (in case you want to incorporate this into a future release):
<?php/**
* TO SUBSCRIBE:
* http://myurl/[email protected]&subsname=test
*
* TO CHECK:
* http://myurl/[email protected]&subsname=test&check=1
*
* TO UNSUBSCRIBE:
* http://myurl/[email protected]&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 checkedif ($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$tableWHEREes_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$tableWHEREes_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.