title: How to import database connection class in another class in php
body: <p>I am going to import DatabaseConnector class in Controller class. DatabaseConnector class contains database connection queries. Both classes are different php file.</p>
  
  <p>Here is my code.</p>
  
  <p>DatabaseConnector:</p>
  
  <pre><code>class DatabaseConnector
  {
      public $con;
      //function for getting connected to database
      public function getConnection()
      {
          $con=mysqli_connect("localhost","root","","abcd");
          // Check connection
          if (mysqli_connect_errno()) {
            echo "Failed to connect to MySQL: " . mysqli_connect_error();
          }
          return $con;
      }
      public function closeConnection()
      {
          mysqli_close($con);
      }
  }
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>include "database_connector.php";
      $dc = new DatabaseConnector();
      $con = $dc-&gt;getConnection();
  class Controller
  {
  
      public function __construct(){
  
      }
  
      public function insertData()
      {
  
          $name = "Abcde";
          $sql = "insert into user_details values('".$name."')";
          mysql_query($con, $sql);
      }
  
  
  }
  </code></pre>
  
  <p>Where i am wrong in this code. it shows me error on mysql_query($con,$sql): $con in undefined variable;
  and mysql_query() requires two parameters</p>
  
  <p>Please help me.</p>