+ 2

Why I have this scope problem in PHP?

Two files: "a.php" and "b.php" a.php (I require some constant to fill in the function (This is ok) $link = mysqli_connect(W,X,Y,Z); b.php (I need the $link for a query) require 'a.php' (I also tried 'include') $result = mysqli_query($link, "SQL STATEMENT IN HERE"); OK, the problem is that PHP shows a warning of UNDEFINED VARIABLE link. I tried everything but still doesn't work. Any idea?

28th Nov 2016, 12:12 AM
Iván
Iván - avatar
2 odpowiedzi
+ 2
a.php $link = mysqli_connect(W,X,Y,Z); b.php require 'a.php'; $result = mysqli_query($link, "SQL STATEMENT IN HERE"); ------------ This should work, but it doesn't. I've tried with global, and that doesn't work neither
28th Nov 2016, 2:51 PM
Iván
Iván - avatar
0
are you using this Mysqli_query() within a function.? if yes then use global $link, after declaration of that function like.. function FuncName(){ global $link; //……your code }
28th Nov 2016, 7:06 AM
santosh ojha
santosh ojha - avatar