id; }
public function getFirst() { return $this->first; }
public function getLast() { return $this->last; }
public function getGender() { return $this->gender; }
public function getSalary() { return $this->salary; }
}
$first = filter_input(INPUT_GET, "firstName");
$last = filter_input(INPUT_GET, "lastName");
try {
// Connect to the database.
$con = new PDO("mysql:host=localhost;dbname=supercoders",
"supercoders", "sesame");
$con->setAttribute(PDO::ATTR_ERRMODE,
PDO::ERRMODE_EXCEPTION);
$query = "SELECT * FROM people";
// Fetch the matching database table rows.
$data = $con->query($query);
$data->setFetchMode(PDO::FETCH_CLASS, "Person");
// We're going to construct an HTML table.
print "
\n";
// Fetch the database field names.
$result = $con->query($query);
$row = $result->fetch(PDO::FETCH_ASSOC);
// Construct the header row of the HTML table.
print "
\n";
foreach ($row as $field => $value) {
print "
$field
\n";
}
print "
\n";
// Constrain the query if we got first and last names.
if ((strlen($first) > 0) && (strlen($last) > 0)) {
$query = "SELECT * FROM people ".
"WHERE first = :first ".
"AND last = :last";
$ps = $con->prepare($query);
$ps->bindParam(':first', $first);
$ps->bindParam(':last', $last);
}
else {
$ps = $con->prepare($query);
}
// Fetch the matching database table rows.
$ps->execute();
$ps->setFetchMode(PDO::FETCH_CLASS, "Person");
// Construct the HTML table row by row.
while ($person = $ps->fetch()) {
print "