Skip to content

Instantly share code, notes, and snippets.

@LayneSmith
Last active August 29, 2015 14:17
Show Gist options
  • Select an option

  • Save LayneSmith/8368366d8665351503d6 to your computer and use it in GitHub Desktop.

Select an option

Save LayneSmith/8368366d8665351503d6 to your computer and use it in GitHub Desktop.
//CHECK DUPLICATE IPs
$ip = $_SERVER["REMOTE_ADDR"];
$maxDuplicates = 200;
$sql = "SELECT COUNT(*) FROM --currentTable-- WHERE ip = '$ip'";
$res = $db->query($sql);
$duplicateIP = $res->fetchColumn();
if ($duplicateIP < $maxDuplicates) {}
//SINGLE INSERT QUERY
$currentTable
$columnName
$sql = "INSERT INTO --currentTable-- ($columnName) VALUES (:columnValue)";
$stmt = $db->prepare($sql);
$stmt->bindValue(':answerText', $answerText);
$stmt->execute();
//MULTIPLE INSERT QUERY
$currentTable
$columnName
$value1
$value2
$sql = "INSERT INTO $currentTable ($value1,$value2) VALUES (:value1,:value2)";
$stmt = $db->prepare($sql);
$stmt->bindValue(':value1', $value1);
$stmt->bindValue(':value2', $value2);
$stmt->execute();
//COUNT TOTAL RESPONSES BY COUNTING ROWS
$currentTable
$sql = "SELECT COUNT(*) FROM $currentTable;
$stmt = $db->prepare($sql);
$stmt->execute();
$totalResponses = $stmt->fetchColumn();
//COUNT ALL ANSWERS THAT EQUAL "$testValue"
$currentTable
$columnName
$testValue
$sql = "SELECT $columnName FROM $currentTable WHERE $columnName = $testValue";
$stmt = $db->prepare($sql);
$stmt->execute();
$valueTotal = $stmt->rowCount();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment