有人可以帮助我理解为什么__construct()没有按预期工作?或者为什么$ link正在未定义?
我收到了错误:
注意:未定义的变量:第29行的D:\ wamp \ www \ OI_WORK \ forms \ Projeto_Interface \ ONGOING \ php \ class.php中的链接
这是第29行:
$consulta = mysqli_query($this->link, $query) or die("Error consulta" . mysqli_error($link));
$ link在这里定义:
class DB{
private $link;
private $_DEFINICOES;
__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));
}
我在类controleUsuario中的私有函数中调用此类DB,这会生成上述错误
private function logar(){
$banco = new DB();
$retorno = $banco->consultarDB("
SELECT `idusuario`
FROM usuariosbeta
WHERE idusuario = {$_SESSION['login']}");
print ("numero de linhas" . $retorno->num_rows);
}
这是调用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();
}
}
的问候,
答案 0 :(得分:0)
在专家朋友的帮助下发现错误
$consulta = mysqli_query($this->link, $query) or die("Erro consulta" . mysqli_error($this->link));
错
mysqli_error($link));
分辩
mysqli_error($this->link));