title: Fetch data from database using MySQLi
body: <p>I want to fetch data from database using MySQLi. But I am having an error in it. Please review my code and give me suggestions to improve it.</p>
  
  <p>Code from config.php:</p>
  
  <pre><code>   public function select_data_from_db($table_name ,$run){
     $stmt=$run-&gt;prepare("SELECT * FROM ".$table_name); 
     $stmt-&gt;execute();
     $result = $stmt-&gt;get_result();
     $total_count=$result-&gt;num_rows;
     $result= array();
    if($total_count&gt;0){
    while ($row = mysqli_fetch_array($query)) {
    $result[] = $row;
    }
    }
    return $result;
   }
  </code></pre>
  
  <p>Code from index.php :</p>
  
  <pre><code>    &lt;?php
     $myrow=$obj-&gt;select_data_from_db("home_slider"); ?&gt;
    &lt;tr&gt;
    &lt;td&gt;&lt;?php echo  $myrow['id']; ?&gt; &lt;/td&gt;
    &lt;td&gt;&lt;?php echo  $myrow['title']; ?&gt; &lt;/td&gt;
    &lt;td&gt;&lt;?php echo  $myrow['description']; ?&gt; &lt;/td&gt;
    &lt;/tr&gt;
  </code></pre>
  
  <p>error which i am getting :</p>
  
  <p>Warning: Missing argument 2 for main::select_data_from_db(), called in D:\Xampp\htdocs\admin\slider_fetch_data.php on line 24 and defined in D:\Xampp\htdocs\admin\config.php on line 113</p>
  
  <p>Notice: Undefined variable: conn in D:\Xampp\htdocs\admin\config.php on line 115</p>
  
  <p>Fatal error: Call to a member function prepare() on null in D:\Xampp\htdocs\admin\config.php on line 115</p>