title: Including my connection.php in a function doesn't work php
body: <p>Working on a small project with some simple sql query injection in my php file. I have created a functions.php file with a function called <code>function displayimage()</code>. I include my function file in my index file and use the function like so </p>
  
  <p>index.php</p>
  
  <pre><code>            &lt;div class="col-lg-2"&gt;
                &lt;?php displayimage(); ?&gt;
              &lt;/div&gt;
  </code></pre>
  
  <p>Functions.php</p>
  
  <pre><code> function displayimage()
  {
  
  $dbCon = mysqli_connect("localhost", "root", "root", "testdb");
  
  if (mysqli_connect_errno()) {
      echo "Failed to connect: " . mysqli_connect_error();
  }
  
  $sql= "SELECT * FROM `images` ORDER BY `images`.`id` DESC ";
  
  $query=mysqli_query($dbCon, $sql);
  
  if ($row = mysqli_fetch_array($query))
  {
      echo '&lt;img class="img-responsive" style="margin-top: 10px;" src="data:image;base64,'.$row[2].' "&gt; ';
  }
  
  mysqli_close($dbCon);
  
   }
   ?&gt;
  </code></pre>
  
  <p>So it works fine but.. I tried to clean my code by putting the database connection in a seperate file, and including it like <code>include('connection.php');</code>. Unfortunately my code doesn't work anymore, and the content won't show up at my index file. My PHPStorm says that <code>$dbCon</code> is a undefinable variable now. What am I doing wrong here?</p>
  
  <p>new functions.php</p>
  
  <pre><code>function displayimage()
  {
  
  include('connection.php');
  
  $sql= "SELECT * FROM `images` ORDER BY `images`.`id` DESC ";
  
  $query=mysqli_query($dbCon, $sql);
  
  if ($row = mysqli_fetch_array($query))
  {
      echo '&lt;img class="img-responsive" style="margin-top: 10px;" src="data:image;base64,'.$row[2].' "&gt; ';
  }
  
  mysqli_close($dbCon);
  
   }
   ?&gt;
  </code></pre>
  
  <p>connection.php</p>
  
  <pre><code>$dbCon = mysqli_connect("localhost", "root", "root", "testdb");
  
  if (mysqli_connect_errno()) {
  echo "Failed to connect: " . mysqli_connect_error();
  }
  </code></pre>