$city = "Amersfoort";
if ($stmt = $mysqli->prepare("SELECT District FROM City WHERE Name=?")) {
$stmt->bind_param("s", $city);
$stmt->execute();
$stmt->bind_result($district);
$stmt->fetch();
printf("%s is in district %s\n", $city, $district);
$stmt->close();
}
This brings many questions:
- What is s
on the line 4? Do I need to bother with that?
- What if I needed two conditions on SQL query? SELECT something FROM table WHERE x=? OR y=?
?
- Why bind_param("s", $city)
and not bind_param("daniweb", $city)
? How does that affect query anyhow if the only usage is below when echoing?
I've been told to used "bind params" in other topic on here. But I don't understand it.