Example #1
0
function generateUniqueId()
{
    $isUnique = false;
    $id;
    do {
        $id = generateRandomLegibleString();
    } while (doesIdExist($id));
    return $id;
}
Example #2
0
//connects to database
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//shows errors
//checks if ID exists
function doesIdExist($employeeId, $conn)
{
    $stmt = $conn->prepare("SELECT employee_id FROM employee WHERE employee_id = :employee_id");
    $stmt->bindParam(':employee_id', $employeeId);
    $stmt->execute();
    if ($stmt->rowCount() > 0) {
        return true;
    } else {
        return false;
    }
}
$r = doesIdExist($employeeId, $conn);
if ($r == true) {
    echo "<b>Employee Data Already Exists</b>";
    header("refresh:5;url=http://localhost/OPHION/index.html");
} else {
    $em = new Employee();
    $em->createEmployee($employeeId, $name, $address1, $address2, $city, $state, $zip, $mainPhone, $altPhone, $isFullTime);
    $em->insertEmployee($conn);
    echo "<b>Employee Data Saved!</b>";
    header("refresh:5;url=http://localhost/OPHION/index.html");
    /* Redirect browser */
}
exit;
/*to crash server 
for ($x = 0; $x <= 1000000; $x++) {
	$stmt->execute();
$sql = "DELETE from dolphin where id=:id";
$statement = $db->prepare($sql);
$sql_values = [':id' => 4];
$statement->execute($sql_values);
/***************************************************************************************************
    Insert Dolphins
***************************************************************************************************/
if (!doesIdExist(3)) {
    $sql = "INSERT into dolphin (id, type, name) values (:id, :type, :name)";
    $statement = $db->prepare($sql);
    $sql_values = [':id' => 3, ':type' => 'Ancient Murder Squid', ':name' => 'Cthulhu'];
    $statement->execute($sql_values);
} else {
    return "Already Exists";
}
if (!doesIdExist(4)) {
    $sql = "INSERT into dolphin (id, type, name) values (:id, :type, :name)";
    $statement = $db->prepare($sql);
    $sql_values = [':id' => 4, ':type' => 'Ancient', ':name' => 'Abraxas'];
    $statement->execute($sql_values);
} else {
    return "Already Exists";
}
?>


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Database Connection</title>