You cannot use bind_result
with SELECT *
. You need to either specify the fields in the SELECT
:
SELECT name, username
And specify each variable in the bind_result
.
$result->bind_result($name, $username);
(Note that $result->fetch()
just populates the variables from bind_result
, it doesn't return the data, it returns a boolean.)
public function getProfile($id){
if($result = $this->link->prepare("SELECT name,username FROM users WHERE id =?")){
$result->bind_param("s", $id);
$result->execute();
$result->bind_result($name, $username);
if($result->num_rows !=0 && $result->fetch()){
return array('name' => $name, 'username' => $username);
}else{
return array("error"=>"Profile-Not-Found");
}
}
}
Or use get_result()
to get the entire row:
public function getProfile($id){
if($result = $this->link->prepare("SELECT * FROM users WHERE id =?")){
$result->bind_param("s", $id);
$result->execute();
if($result->num_rows !=0){
$row = $result->get_result();
return $row->fetch_assoc();
}else{
return array("error"=>"Profile-Not-Found");
}
}
}