I am currently learning PHP concepts and just can not figure out how to properly bind a query. According to PDO manual, queries are bound only if they are of type string, int, float, etc. My first question is: "Do I need to bind date?" If yes, which parameters use. Otherwise, I need to bind some attributes of a relation to insert and what to do with remaining which are not of these types mentioned above? Here is my code:
public function addCustomer($fname, $lname, $email, $dob, $hashedPwd, $hash)
{
$customer = new Customer($fname, $lname, $email, $dob, $hashedPwd);
$sql = $this->pdo->prepare("INSERT INTO customer(fname, lname, email, date_of_birth, password, hash, active)"
. " VALUES(:fname, :lname, :date_of_birth, :email, :password, :hash, :active)");
$sql->bindValue(':fname', $customer->getFname(), PDO::PARAM_STR);
$sql->bindValue(':lname', $customer->getLname(), PDO::PARAM_STR);
$sql->bindValue(':email', $customer->getEmail(), PDO::PARAM_STR);
$sql->bindValue(':password', $customer->getPassword(), PDO::PARAM_STR);
$sql->bindValue(':hash', $hash, PDO::PARAM_STR);
$sql->bindValue(':active', 0, PDO::PARAM_INT);
try {
$sql->execute(['date_of_birth' => $dob]);
echo "SUCCESS" . "<br>";
}catch (PDOException $e) {
$e->getMessage();
}
}