title: mysqli_query() expects parameter 1 to be mysqli, object given
body: <p>I'm trying to create a class which can be used for connecting to MySQL database.  This is my code:</p>
  <p>The class:</p>
  <pre><code>&lt;?php
  
  class createCon  {
      var $host = 'localhost';
      var $user = 'root';
      var $pass = '';
      var $db = 'example';
      var $myconn;
  
      function connect() {
          $con = mysqli_connect($this-&gt;host, $this-&gt;user, $this-&gt;pass, $this-&gt;db);
          if (!$con) {
              die('Could not connect to database!');
          } else {
              $this-&gt;myconn = $con;
              echo 'Connection established!';}
          return $this-&gt;myconn;
      }
  
      function close() {
          mysqli_close($myconn);
          echo 'Connection closed!';
      }
  
  }
  </code></pre>
  <p>And this is where I try to query the database:</p>
  <pre><code>&lt;?php
  
  include 'connect.php';
  
  $connection = new createCon();
  $connection-&gt;connect();
  
  $query = 'SELECT * FROM  `nickname`';
  $result = mysqli_query($connection, $query);
  
  if($numrows = mysqli_num_rows($result)) {
      echo $numrows;
      while ($row = mysqli_fetch_assoc($result)) {
          $dbusername = $row['nick'];
          $dbpassword = $row['pass'];
          echo $dbusername;
          echo $dbpassword;
      }
  }
  </code></pre>
  <p>I get the following error when I try to make a query:</p>
  <blockquote>
  <p>Warning: mysqli_query() expects parameter 1 to be mysqli, object given in C:\wamp\www\uppgift 1 kompletering\test.php on line 13</p>
  </blockquote>