I have simple php script but from some reason when i call getUserRoles function from another script i get "Undefined variable: mysqli" as you can see i included dbConnect script. (Path is 1000% correct)
<?php
require_once '../dbConnect.php';
function getUserRoles() {
$stmt = $mysqli->prepare("SELECT ur.roleName from user_role as ur where ur.userId = ?");
$stmt->bind_param("i", $_SESSION["id"]);
$stmt->execute();
$stmt->bind_result($roleName);
$roles = array();
$stmt->bind_result($roleName);
while ( $stmt->fetch() ) {
$roles[] = $roleName;
}
return $roles;
}
?>
And from this script i want to call getUserRoles(), but when i call function i get "Undefined variable: mysqli" and i have no idea why, can anyone tell me where i'm making mistake ?
<?php
require_once '../dbConnect.php';
require_once '../security/securityService.php';
getUserRoles();
?>
In that script i include securityService.php script where i have getUserRoles() and i successfully make function call, but inside that function i cant connect to database.