I can’t connect to the database

Asked

Viewed 42 times

0

Hello good night I am studying php, but when it comes time to make connection with the BD, does not connect at all, the names of the bank are correct, the already imported the bank and nothing anyone knows what can be?

Connection to the Database

<?php

   /**
  * classe que trata de conexao com o BD e operações
   */
   class Conexao {

private $host;
private $user;
private $senha;
private $bd;
private $link;
public  $query;
public  $lista;
//private $tabela;


/**
 * funcao construtora que inicia o link caso esteja null
 */
function __construct() {



    if ($this->link == NULL):
         $this->getConexao();

    endif;


}

/**
 * faz a conexao caso não tenha valores no LINK
 */
public function getConexao(){

    $this->host  = 'localhost';
    $this->user  = 'root';
    $this->senha = '';
    $this->bd    = 'imob';


  $this->link = mysql_connect($this->host, $this->user, $this->senha) or die('Erro de conexao');
  mysql_select_db($this->bd, $this->link);
        mysql_set_charset('UTF8', $this->link);

}


/**
*
* @param type $sql -  passo a minha sql
  */
   public function ExecSQL($sql){

   $this->query =  mysql_query($sql, $this->link) or die(mysql_error());


}

 /**
 *
 * @return type -   retorna a lista de registros
 */
    public function ListarDados(){



            $this->lista = mysql_fetch_assoc($this->query);

    return $this->lista;


}

   /**
  *
    * @return type -  retorna a contagem dos registros s query
    */

public function TotalRegistros() {

    return mysql_num_rows($this->query);

}

  }
  • 1

    User and the Password ? It would be easier if you edit the question and put the code. I recommend you to do the Tour to learn how the community and accessing the session Asking in Help Center.

  • I put mysqli, but still the bank does not connect

  • Is the Mysql service port correct? Use mysqli_connect_error to verify which error. It is easier to fix the problem.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.