How do I allow a function to access a database connection without using GLOBAL?
config.php
DEFINE (\'DB_HOSTNAME\', \'hostname\');
DEFINE (\'DB_DAT
There are two ways one is by passing arguments and the other by using function closure like @Ondrej said. But I wonder both of these require you to modify the code if that is the case, then I would suggest you to use global
keyword.
You can use global
keyword to get the scope of variable $dbc
Try this..
function something()
{
global $dbc;
$info = mysqli_query($dbc, "SELECT info FROM text") or die("Error: ".mysqli_error($dbc));
}
(OR)
Try this...
function something()
{
$dbc = func_get_arg(0);
$info = mysqli_query($dbc, "SELECT info FROM text") or die("Error: ".mysqli_error($dbc));
}
& do this ....
$query = something($dbc);