title: Warning: mysqli_query() expects parameter 1 to be mysqli, object given in
body: <p>Hi i am trying to change mysql to mysqli but my script is not working. after changing to mysqli</p>
  
  <p>Database.php</p>
  
  <pre><code>&lt;?php
  
   include("constants.php");
   class MySQLDB 
   {
  
     var $connection;         //The MySQL database connection
     var $num_active_users;   //Number of active users viewing site
     var $num_active_guests;  //Number of active guests viewing site
     var $num_members;        //Number of signed-up users
    /* Note: call getNumMembers() to access $num_members! */
  
   /* Class constructor */
   function MySQLDB(){
  
    /* Make connection to database */
   $this-&gt;connection= mysqli_connect(DB_SERVER, DB_USER, DB_PASS,DB_NAME);
   // Check connection 
   if (mysqli_connect_errno())
   {
   echo "Failed to connect to MySQL: " . mysqli_connect_error();
     }
  
  
    $this-&gt;num_members = -1;
  
    if(TRACK_VISITORS){
       /* Calculate number of users at site */
       $this-&gt;calcNumActiveUsers();
  
       /* Calculate number of guests at site */
       $this-&gt;calcNumActiveGuests();
         }
    }
  
    function confirmUserPass($username, $password){
  
    /* Add slashes if necessary (for query) */
    if(!get_magic_quotes_gpc()) {
        $username = addslashes($username);
    }
  
    /* Verify that user is in database */
    $q = "SELECT password FROM ".TBL_USERS." WHERE username = '$username'";
    $result = mysqli_query($this-&gt;connection,$q);
    if(!$result || (mysqli_num_rows($result) &lt; 1)){
       return 1; //Indicates username failure
    }
  
    /* Retrieve password from result, strip slashes */
    $dbarray = mysqli_fetch_array($result);
    $dbarray['password'] = stripslashes($dbarray['password']);
    $password = stripslashes($password);
  
    /* Validate that password is correct */
    if($password == $dbarray['password']){
       return 0; //Success! Username and password confirmed
    }
    else{
       return 2; //Indicates password failure
    }
    }
  
  
    function confirmUserID($username, $userid){
  
    /* Add slashes if necessary (for query) */
    if(!get_magic_quotes_gpc()) {
        $username = addslashes($username);
    }
  
    /* Verify that user is in database */
    $q = "SELECT userid FROM ".TBL_USERS." WHERE username = '$username'";
    $result = mysqli_query($this-&gt;connection,$q);
    if(!$result || (mysqli_num_rows($result) &lt; 1)){
       return 1; //Indicates username failure
    }
  
    /* Retrieve userid from result, strip slashes */
    $dbarray = mysqli_fetch_array($result);
    $dbarray['userid'] = stripslashes($dbarray['userid']);
    $userid = stripslashes($userid);
  
    /* Validate that userid is correct */
    if($userid == $dbarray['userid']){
       return 0; //Success! Username and userid confirmed
    }
    else{
       return 2; //Indicates userid invalid
     }
     }
  
  
     function usernameTaken($username){
  
    if(!get_magic_quotes_gpc()){
       $username = addslashes($username);
    }
    $q = "SELECT username FROM ".TBL_USERS." WHERE username = '$username'";
    $result = mysqli_query($this-&gt;connection,$q);
    return (mysqli_numrows($result) &gt; 0);
    }
  
  
     function usernameBanned($username){
  
    if(!get_magic_quotes_gpc()){
       $username = addslashes($username);
    }
    $q = "SELECT username FROM ".TBL_BANNED_USERS." WHERE username = '$username'";
    $result = mysqli_query($this-&gt;connection,$q);
    return (mysqli_numrows($result) &gt; 0);
    }
  
  
     function addNewUser($username, $password, $email){
  
    $time = time();
    /* If admin sign up, give admin user level */
    if(strcasecmp($username, ADMIN_NAME) == 0){
       $ulevel = ADMIN_LEVEL;
    }else{
       $ulevel = USER_LEVEL;
    }
     $q = "INSERT INTO ".TBL_USERS." VALUES ('$username', '$password', '0', $ulevel,     '$email', $time)";
    return mysqli_query($this-&gt;connection,$q);
     }
  
     function updateUserField($username, $field, $value){
    $q = "UPDATE ".TBL_USERS." SET ".$field." = '$value' WHERE username = '$username'";
    return mysqli_query($this-&gt;connection,$q);
     }
  
     function getUserInfo($username){
  
    $q = "SELECT * FROM ".TBL_USERS." WHERE username = '$username'";
    $result = mysqli_query($this-&gt;connection,$q);
    /* Error occurred, return given name by default */
    if(!$result || (mysqli_num_rows($result) &lt; 1)){
       return NULL;
     }
    /* Return result array */
    $dbarray = mysqli_fetch_array($result);
    return $dbarray;
     }
  
  
     function getNumMembers(){
  
    if($this-&gt;num_members &lt; 0){
       $q = "SELECT * FROM ".TBL_USERS;
       $result = mysqli_query($this-&gt;connection,$q);
       $this-&gt;num_members = mysqli_num_rows($result);
     }
    return $this-&gt;num_members;
     }
  
  
     function calcNumActiveUsers(){
  
    /* Calculate number of users at site */
    $result = mysqli_query($this-&gt;connection,"SELECT * FROM ".TBL_ACTIVE_USERS);
    $this-&gt;num_active_users = mysqli_num_rows($result);
     }
  
  
     function calcNumActiveGuests(){
  
    /* Calculate number of guests at site */
    $q = "SELECT * FROM ".TBL_ACTIVE_GUESTS;
    $result = mysqli_query($this-&gt;connection,$q);
    $this-&gt;num_active_guests = mysqli_num_rows($result);
    }
  
    function addActiveUser($username, $time){
  
    $q = "UPDATE ".TBL_USERS." SET timestamp = '$time' WHERE username = '$username'";
    mysqli_query($this-&gt;connection,$q);
  
    if(!TRACK_VISITORS) return;
    $q = "REPLACE INTO ".TBL_ACTIVE_USERS." VALUES ('$username', '$time')";
    mysqli_query($this-&gt;connection,$q);
    $this-&gt;calcNumActiveUsers();
    }
  
   /* addActiveGuest - Adds guest to active guests table */
    function addActiveGuest($ip, $time){
  
    if(!TRACK_VISITORS) return;
    $q = "REPLACE INTO ".TBL_ACTIVE_GUESTS." VALUES ('$ip', '$time')";
    mysqli_query($this-&gt;connection,$q);
    $this-&gt;calcNumActiveGuests();
   }
  
  
     function removeActiveUser($username){
  
    if(!TRACK_VISITORS) return;
    $q = "DELETE FROM ".TBL_ACTIVE_USERS." WHERE username = '$username'";
    mysqli_query($this-&gt;connection,$q);
    $this-&gt;calcNumActiveUsers();
    }
  
  
     function removeActiveGuest($ip){
  
    if(!TRACK_VISITORS) return;
    $q = "DELETE FROM ".TBL_ACTIVE_GUESTS." WHERE ip = '$ip'";
    mysqli_query($this-&gt;connection,$q);
    $this-&gt;calcNumActiveGuests();
    }
  
     function removeInactiveUsers(){
  
    if(!TRACK_VISITORS) return;
    $timeout = time()-USER_TIMEOUT*60;
    $q = "DELETE FROM ".TBL_ACTIVE_USERS." WHERE timestamp &lt; $timeout";
    mysqli_query($this-&gt;connection,$q);
    $this-&gt;calcNumActiveUsers();
     }
  
    /* removeInactiveGuests */
    function removeInactiveGuests(){
    if(!TRACK_VISITORS) return;
    $timeout = time()-GUEST_TIMEOUT*60;
    $q = "DELETE FROM ".TBL_ACTIVE_GUESTS." WHERE timestamp &lt; $timeout";
    mysqli_query($this-&gt;connection,$q);
    $this-&gt;calcNumActiveGuests();
    }
  
  
     function query($query){
  
    return mysqli_query($this-&gt;connection,$query);
     }
  };
  
  /* Create database connection */
  
  $database = new MySQLDB;
  
  ?&gt;
  </code></pre>
  
  <p>index.php</p>
  
  <pre><code> &lt;?php
   include("include/database.php");
  
   $result = mysqli_query($database,"SELECT * FROM users");
  
   while($row = mysqli_fetch_array($result))
    {
    echo $row['username'] . " " . $row['achternaam'];
    echo "&lt;br&gt;";
     }
  
   mysqli_close($database);
   ?&gt;
  </code></pre>
  
  <p>The errors that i have is:</p>
  
  <pre><code> Warning: mysqli_query() expects parameter 1 to be mysqli, object given in      C:\xampp\htdocs\follow\index.php on line 4
  
   Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in C:\xampp\htdocs\follow\index.php on line 6
  
   Warning: mysqli_close() expects paramet   er 1 to be mysqli, object given in C:\xampp\htdocs\follow\index.php on line 12
  </code></pre>
  
  <p>I know that i can not use the $this->connection outsite the function and tried that with a GLOBAL $connection but is also not working?</p>