好的,所以我有一个叫做用户的类。在该课程中,我有几个公共变量,例如“ key”(用于加密)。还有几个函数,但唯一相关的是get_all()。该函数从数据库获取所有数据并将其存储在这些公共变量中(因此我可以从另一个类访问它们)。
class User
{
public $uuid = "";
public $key = "";
public function get_all()
{
$db = mysqli_connect('localhost', 'root', 'password', 'BOTNET');
$sql = $db->prepare("SELECT * FROM USERS WHERE uuid=?");
$sql->bind_param('s', $this->uuid);
if ($sql->execute())
{
if ($all_info = $sql->get_result()) // This fails
{
while ($row = $all_info->fetch_assoc())
{
$this->key = $row["_Key"];
...
}
}
error_log("ERROR"); // Gets logged
error_log(mysqli_error($db)); // This doesnt log anything
}
}
现在是问题所在:我有第二个文件,可以在其中说index.php,我可以通过以下方式访问用户类:
$user = new User();
$user->set_uuid(some_uuid);
$user->get_all(); (Set all public variables)
$key = $user->key; (Now I should have a string with the users key, but no: $key is just empty)
此确切的代码在不同的类中以及在开关之外时都适用
开关:
switch ($_POST["action"])
{
case 1:
$user = new User();
$user->set_uuid(some_uuid);
$user->get_all(); (Set all public variables)
$key = $user->key; (Now I should have a string with the users key)
break;
...
}