Reputation: 3442
If this is my code:
$mysqli = new mysqli("localhost", "user", "password", "mydb");
$city = "Some";
$q = "SELECT District FROM City WHERE (Name=? OR ? IS NULL)";
if ($stmt = $mysqli->prepare($q)) {
// How to Bind $city here?
}
How can I bind $city
to both ?
s?
Or is there any better way to do this?
Upvotes: 3
Views: 526
Reputation: 57322
you can do this by
$stmt -> bind_param("for first ?", 'for second ?');
or try like
/* Bind our params */
$stmt->bind_param('ss', $Name, $city);
/* Set our params */
$Name= "hello";
$city= "city";
/* Execute the prepared Statement */
$stmt->execute();
The values can be:
i - Integer
d - Decimal
s - String
b - Blob (sent in packets)
Upvotes: 4