Hello i just want write own function to get option value from mysql. My index.php file looks in this way:
<?
include ('config.php'); // here i have database connection details
include ('global-functions.php');
include ('minifier.php');
include ('cache-start.php');
?>
<!DOCTYPE html>
<html lang="jezyk strony z bazy danych">
USTAWIC META! sekcje head<br>
Sprawdzić czy dodac przekierowanie w php z www na bez www !!
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
(...) rest of the file
config.php file looks:
<?php
$host = "localhost";
$dbname = "xxxx";
$username = "xxx";
$password = "xxxx";
// Create connection
$conn = new mysqli($host, $username, $password, $dbname);
?>
Now i try to do function to take specified option, i put this function in global-functions.php:
<?php
// Get option
function get_option( $option_name ) {
$sql = "SELECT opcja_value FROM opcje WHERE opcja_name='" . $option_name . "'";
$result = mysqli_fetch_array($conn->query($sql));
return $result[$option_name];
}
?>
Now i going to call function to get value of my option. So:
echo get_option('cache');
or doing simple if :
if ( get_option('cache') == '1' ) {
// do stuff
} else {
echo 'option disabled, sorry :(';
}
After call function i get Fatal error:
Fatal error: Call to a member function query() on null in /framework/includes/global-functions.php on line 10