我是PHP新手,想知道为什么我的like查询只返回一个值
这是我的模特
//For search
public function getSearchResults($username){
$stmt = $this->_connection->prepare("SELECT * FROM users WHERE username LIKE :username");
$stmt->execute(['username' => '%'.$username.'%']);
$stmt->setFetchMode(PDO::FETCH_CLASS, "User");
return $stmt->fetch();
}
然后在我的控制器中
function search($name){
//Get search results
$searchResults = $this->model('User');
$searchResults = $searchResults->getSearchResults($name);
$data = (array) $searchResults;
$this->view('User/search', $data);
}
但是它只返回1个结果而不是3个结果。(我有4个用户名,其中带有“ hi”,但仅返回1个结果)