我有一个示例代码:
class DBConnect {
private $connect = null;
private $query = null;
public $result = 0;
public $data = null;
public $_result;
function connect() {
$this->connect = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS) or die("Can't connect database");
mysql_query("set names 'utf8'");
mysql_select_db(MYSQL_NAME, $this->connect);
}
function close() {
if($this->connect) {
mysql_close($this->connect);
}
}
function query($sql) {
$this->query = mysql_query($sql);
if(!$this->query) {
echo "Error: " . mysql_error();
exit;
}
}
function get_data($category_id) {
$sql = 'SELECT id, name FROM category WHERE id='.$category_id;
query($sql); // This is error
$row = mysql_fetch_object($query);
$data = $row->category;
return $data;
}
}
当我运行调试时错误是:Call to undefined function query() in line...
,如何修复它?