title: How to connect to database using mvc in php
body: <p><strong>dbconnect.php</strong></p>
  <pre><code>class dbconnect
  {
      public function connect()
      {
          $host = 'localhost';
          $user = 'root';
          $pass = '';
          $db = 'demo';
          $connection = mysqli_connect($host, $user, $pass, $db);
          return $connection;
      }
  }
  </code></pre>
  <p><strong>dao.php</strong></p>
  <pre><code>include 'dbconnect.php';
  class dao extends dbconnect
  {
      private $conn;
      function __construct()
      {
          $dbcon = new dbconnect();
          $conn = $dbcon-&gt;connect();
      }
      function select($table, $where = '', $other = '')
      {
          if (!$where = '') {
              $where = 'where' . $where;
          }
          $sele = mysqli_query($this-&gt;conn, &quot;SELECT * FROM  $table $where $other&quot;) or die(mysqli_error($this-&gt;conn));
          echo $sele;
          return $sele;
      }
  }
  </code></pre>
  <p><strong>controller.php</strong></p>
  <pre><code>include 'dao.php';
  $d = new dao();
  if (isset($_POST['btn_login'])) {
      extract($_POST);
      $username = $_POST['user_name'];
      $pswd = $_POST['pswd'];
      $sel = $d-&gt;select(&quot;users&quot;, &quot;email_id = '&quot; . $username . &quot;'AND password='&quot; . $pswd . &quot;'&quot;) or die('error from here');
      $result = mysqli_fetch_array($sel);
      if ($result['email_id'] == $username &amp;&amp; $result['password'] == $pswd) {
          SESSION_START();
          $_SESSION['user_name'] = $result['email_id'];
          $_SESSION['message'] = 'Invalid Username Or Password';
          header(&quot;location:index.php&quot;);
      } else {
          $_SESSION['error'] = 'Invalid Username Or Password';
      }
  }
  </code></pre>
  <p>I got an error</p>
  <ul>
  <li><p>Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /opt/lampp/htdocs/ankit_demo/dao.php on line 13</p>
  </li>
  <li><p>Warning: mysqli_error() expects parameter 1 to be mysqli, null given in /opt/lampp/htdocs/ankit_demo/dao.php on line 13</p>
  </li>
  </ul>
  <p>Please help me to solve this.</p>