我将编辑问题以使其更清晰,以便您可以看到我现在得到的内容,并更容易理解问题。
<?php
$mysqli = new mysqli("localhost", "user", "password", "test");
class building
{
private $mysqli;
public $buildingid;
public $userid;
public $buildinglevel;
public function __construct($buildingid, $userid, \mysqli $mysqli)
{
$this->buildinglevel;
$this->mysqli = $mysqli;
}
public function getLevel()
{
return $this->mysqli->query("SELECT ".$this->buildingid." FROM worlds WHERE city_userid=".$this->userid."");
}
}
}
?>
然后我用它来创建和使用函数:
$cityHall = new building("cityHall",$user['id'],$mysqli);
echo $cityHall->getLevel();
这结果是空白的,没有任何反应。