我有一个错误,就是试图获取非对象的属性。请帮助我做错了
错误消息:注意:尝试获取非对象的属性,这是代码的检查结果部分。
<?php
class search {
private $mysqli;
public function __construct() {
$this->connect();
}
private function connect() {
$this->mysqli = new mysqli( 'localhost', 'root', '', 'csvfiles' );
}
public function search($search_term) {
$sanitized = $this->mysqli->real_escape_string($search_term);
// Run the query
$query = $this->mysqli->query("
SELECT title, `COL 1`, `COL 2`
FROM `search`
WHERE `title` LIKE '%{$sanitized}%'
OR `body` LIKE '%{$sanitized}%'
");
// Check results
if ( ! $query->num_rows ) {
return false;
}
// Loop and fetch objects
while( $row = $query->fetch_object() ) {
$rows[] = $row;
}
// Build our return result
$search_results = array(
'count' => $query->num_rows,
'results' => $rows,
);
return $search_results;
}
}