I'm new to mysqli prepare statement and was surprised to find out the || doesn't work as expected in mysqli prepare statement query.
I have a function which check whether the user registered, and its evaluation should be based upon the unique row id and email address.Besides, since the id column and the email column are of different type, which are Int(11)
and VARCHAR
respectively, so I assumed it's going to have some trouble using bind_param
because the different data type
public function checkUserRegistered($iden){
//The iden can be either a id or a email address
$stmt = $this->connection->prepare("SELECT `id` FROM `$this->table_name` WHERE (`email`= ? || `id`= ?) LIMIT 1 ");
$stmt->bind_param('s',$iden); // s or i ?
if($stmt->execute()){
$result = $stmt->get_result();
if($result->num_rows ==1){
$stmt->close();
return true;
}else{
return false;
}
}
}
What is the right way of doing this, do I have to use separate functions instead?
You need to bind two params like this:
as you have set two '?'.
s means string, i means integer, b is blob and d is double.