php class Cannot use object of type User as array

I have a user class to get all user data, I tried to show a particular user's email but have error with Fatal error: Cannot use object of type User as array in C:\..., please advise.

class:

class User{

    public function get_user_info($user_id, $mysqli){
        if(empty($user_id)) {
            return null;
        }

        $sql = $mysqli->query("SELECT * FROM `users` WHERE user_id='".$user_id."' LIMIT 1");

        if($sql->num_rows > 0){
            $row = $sql->fetch_array(MYSQLI_BOTH);
            return $row;
        }

        return null;
    }

}

call email:

include('classes/user.php');

$user = new User;
$user->get_user_info($user_id, $mysqli);

echo 'email: '.$user['user_email'];

Answers


$mysqli is never defined in your code.

You cannot use something that was not defined.


Need Your Help

Error: Service instance has no attribute 'SvcDoRun'

python windows winapi service pywin32

Using python 2.7 on windows 7 64 bit machine. I had followed the link http://essiene.blogspot.in/2005/04/python-windows-services.html But getting error when seen in Events Viewer Windows Logs as

How to get data context of a table row when clicking on one of its column, in a reactive table?

javascript meteor

In a reactive table the data context is passed to the full row, I have to fire an event when one of its columns are clicked and then use the data passed to the row.