Fatal error: Call to a member function query() on null in
<p>Hello i just want write own function to get option value from mysql. My index.php file looks in this way: </p>

<pre><code>&lt;?
include ('config.php'); // here i have database connection details
include ('global-functions.php');
include ('minifier.php');
include ('cache-start.php');
?&gt;
&lt;!DOCTYPE html&gt;
&lt;html lang="jezyk strony z bazy danych"&gt;
USTAWIC META! sekcje head&lt;br&gt;
Sprawdzić czy dodac przekierowanie w php z www na bez www !!
&lt;head&gt;

    &lt;meta charset="utf-8"&gt;
    &lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&gt;
    &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;


(...) rest of the file
</code></pre>

<p>config.php file looks: </p>

<pre><code>&lt;?php

$host = "localhost";
$dbname = "xxxx";
$username = "xxx";
$password = "xxxx";

// Create connection
$conn = new mysqli($host, $username, $password, $dbname);

?&gt;
</code></pre>

<p>Now i try to do function to take specified option, i put this function in global-functions.php: </p>

<pre><code>&lt;?php


// Get option

function get_option( $option_name ) {

    $sql = "SELECT opcja_value FROM opcje WHERE opcja_name='" . $option_name . "'";
    $result = mysqli_fetch_array($conn-&gt;query($sql));

    return $result[$option_name];

}

?&gt;
</code></pre>

<p>Now i going to call function to get value of my option. So:</p>

<pre><code>echo get_option('cache');
</code></pre>

<p>or doing simple if :</p>

<pre><code>if ( get_option('cache') == '1' ) {
 // do stuff
} else {
 echo 'option disabled, sorry :(';
}
</code></pre>

<p>After call function i get Fatal error: </p>

<blockquote>
  <p>Fatal error:  Call to a member function query() on null in
  /framework/includes/global-functions.php on line 10</p>
</blockquote>