someone could help me understand why __construct() is not working as expected? Or why $link is being Undefined?
I got error:
Notice: Undefined variable: link in D:\wamp\www\OI_WORK\forms\Projeto_Interface\ONGOING\php\class.php on line 29
This is line 29:
$consulta = mysqli_query($this->link, $query) or die("Error consulta" . mysqli_error($link));
$link is defined here:
class DB{
private $link;
private $_DEFINICOES;
the __construct():
function __construct(){
$this->_DEFINICOES = array(
'database_ip' => "xxxx",
'database_user' => "xxx",
'database_senha' => "xxx",
'database_name' => "xxxx");
$this->link = mysqli_connect( $this->_DEFINICOES['database_ip'], $this->_DEFINICOES['database_user'], $this->_DEFINICOES['database_senha'], $this->_DEFINICOES['database_name']) or die("Error " . mysqli_error($this->link));
}
I call this class DB inside a private function in class controleUsuario and this generate the above error
private function logar(){
$banco = new DB();
$retorno = $banco->consultarDB("
SELECT `idusuario`
FROM usuariosbeta
WHERE idusuario = {$_SESSION['login']}");
print ("numero de linhas" . $retorno->num_rows);
}
here is the function that calls controleUsuario->logar()
public function salvaPost($post){
/* se o post nao estiver nulo ou com valor false atribui ao session */
if( !(($post == false) or ($post == null)) ){
foreach ($post as $key => $valor){
/* segurança post */
$_SESSION[$key] = $valor;
}
$this->segurancaLogin($valor);
$this->logar();
}
}
regards,