0

OK, so I have a class called user. In that class, I have a couple of public variables like "key" (Used for encryption). Also a couple of functions but the only relevant one is get_all(). This function gets all data from a database and stores it in these public variables (So I can access them from another class).

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

        }
}

Now to the problem: I have a second file lets say index.php in there I access the user class in the following way:

$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)

This exact code works in different classes, and when it's outside of the switch

The switch:

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;
    ...
  }

0 Answers0