What I want to do is this:
class DB extends mysqli {
...
}
DB :: connect( ... );
DB :: query( "SELECT * FROM myDB" );
class AnotherClass {
function helloWorld()
{
DB :: query( "SELECT * FROM withoutUsingGlobalKeyword" );
}
}
function functions()
{
DB :: query( "SELECT * FROM withoutUsingGlobalKeyword" );
}
The point of this question is to avoid the use of the ‘global’ keyword like:
global $mysqli;
$mysqli = new mysqli( ... );
class AnotherClass {
function helloWorld()
{
global $mysqli;
$mysqli->query( "SELECT * FROM IDontWantToUseGlobalKeyword" );
}
}
function functions()
{
global $mysqli;
$mysqli->query( "SELECT * FROM IDontWantToUseGlobalKeyword" );
}
A solution for this is to declare the mysqli variable in the $_ENV array, but I don’t want to use $_ENV to manage the MYSQLI, I want to use a static class like DB (Is that possible?)
After of all, I found a solution: