I know thats not the best title for my question but I coulnd't come up with a better one (Suggestions are welcome)
Well, this is my situation, I have 3 files:
1) classDBConn.php - In this file is where I connect to the DB and have some functions like this:
class DBConn{
var $conexion;
private $querySql;
var $respuesta;
var $resultado;
function __construct() {
$this->conexion = @mysqli_connect('localhost', 'root', 'pass', 'dataBase');
if(!$this->conexion){
die('error de conexion('.mysqli_connect_errno().')'.mysqli_connect_error());
}
}
function checkBracketGanador($id_torneo){
$this->querySql = "SELECT COUNT(id_ganador) FROM brackets WHERE id_torneo = '$id_torneo'";
$this->respuesta = mysqli_query($this->conexion,$this->querySql);
$this->resultado = mysqli_fetch_array($this->respuesta);
return $this->resultado[0];
}
// More functions with queries
Note: queries and functions are fine
2)inc_conf.php - In this file is where I create the session and object DBConn. Code:
session_start();
include('classDBConn.php');
$functionsDBConn= new DBConn();
$id_usuario = isset($_SESSION["IDUSUARIO"]) ? $_SESSION["IDUSUARIO"] : false;
3) workingOn.php - In this file is where I make calls to DBConn in order to use those queries. If I do a call like this is just fine:
$res = $functionsDBConn->checkBracketGanador($id_torneo);
echo $res;
But, if I do it inside a function is where everything goes wrong
function test(){
$res = $functionsDBConn->checkBracketGanador($id_torneo);
return $res;
}
$a = test();
echo $a;
I keep getting this error:
Fatal error: Call to a member function checkBracketGanador() on a non-object in .../someFolder/workingOn.php on line 67
I've tried making public functions in classDBConn but didn't work
What I'm doing is calling the function outside the function and sending the result as a parameter to the other function but thats exactly what I want to avoid
Any help is appreciate. Thanks in advance.