Two solutions:
Solution 1: Refractor your code, something along the lines of:
config.php:
$config = array(
"databases" => array(
"my_database" => array(
"host" => "localhost",
"user" => "myusername",
"pass" => "mypassword"
)
)
);
functions.php:
require("config.php");
function connectDB($dbname)
{
global $config;
if (!isset($config["databases"][$dbname]))
return; // error, database info not in $config
$dbc = $config["databases"][$dbname];
$dbcon = mysqli_connect($dbc["host"], $dbc["user"], $dbc["pass"], $dbname);
if (!$dbcon)
return; // unable to connect error goes here
return $dbcon;
}
Note that this is just the bare minimum of a connectDB function. There really should be more error checking in there (for example, on each of the $dbc
keys. It also needs proper error reporting and such, this is just a general hint in the right direction.
Solution 2: Add return
in front of your include...
function connectDB($db_name,$connectorkill,$link) { return include('connectDB.inc.php'); }
Regardless of the solution: You really need some error checking code in your index.php because no matter what you do: Your connectDB function isn't always going to return a valid database connection.