我需要获取某个查询返回的行数,但它让我出现了这个错误
试图在第 18 行的 C:\xampp\htdocs\sample\includes\CheckUsername.php 中获取非对象的属性
这是我的代码:
<?php
class Db_CheckUsername{
protected $_conn;
protected $_username;
protected $_errors = array();
public function __construct($username,$conn){
$this->_username = $username;
$this->_conn = $conn;
}
public function isUsernameAvailable(){
$sql = "SELECT ";
$sql .= "FROM accounts ";
$sql .= "WHERE username = {$this->_username}";
$result = $this->_conn->query($sql);
$numRows = $result->num_rows;
if($numRows == 0){
return true;
}else{
return false;
}
}
}
?>
我该如何解决这个问题?