So I have a class.. In its constructor I include the code which connects me to my database via the mysqli extension:
class MyClass
{
public function __construct()
{
include("dbconnect");
}
}
dbconnect looks like this:
$host = "localhost";
$user = "user";
$pass = "123";
$database = "myDatabase";
$mysqli = new mysqli($host, $user, $pass, $database);
$mysqli->set_charset('utf8-bin');
Now to my problem: Since mysqli can be used OOP-Style, how do I get access to the variable in MyClass?
function doIt()
{
$query = "SELECT * FROM myTable";
$result = $mysqli->multi_query($query);
}
A call to this function results in
Notice: Undefined variable: mysqli in ... on line ... Fatal error: Call to a member function multi_query() on a non-object in ... on line ...
So it seems the scope of the variable is not right. Does anyone know how to fix this? It would be best if MyClass would not need an extra reference or something to mysqli, since I would like to keep it seperated.