+ 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?
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
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
}