My php code looks like this:
$jsonIterator = new RecursiveIteratorIterator(new RecursiveArrayIterator(json_decode(file_get_contents("data.config"), TRUE)), RecursiveIteratorIterator::SELF_FIRST);
foreach ($jsonIterator as $key => $val)
{
if($key == "user")
$user = $val;
else if($key == "pass")
$pass = $val;
else if($key == "server")
$server = $val;
else if($key == "data")
$data = $val;
}
if(!empty($_GET) && isset($_GET['function'])) call_user_func($_GET['function']);
if(!empty($_POST) && isset($_POST['function'])) call_user_func($_POST['function']);
function dbcon()
{
return new mysqli($server,$user,$pass,$data);
}
But when I call dbcon()
, I get undefined variable: user and so forth for the other 3.
Why is this happening and how can I fix it?