My hosting does not connect the bank

0

When the database is loaded, it looks like this:

  

SQLSTATE [HY000] [2002] Connection timed out Fatal error: Call to a   member function prepare () on a non-object in

How can I resolve, to be able to connect? because location works normally.

 <?php
  require_once ('./funcao/conecta.php');
  $conn = conecta();
  $sql = $conn->prepare("SELECT * FROM 'lojao'.'categorias' ORDER BY nome_categoria ASC");
  $sql->execute();
  $sql->setFetchMode(PDO::FETCH_ASSOC);
  while ($linha = $sql->fetch()) {
      $categoriaid = $linha['id_categoria'];
      $nomecategoria = $linha['nome_categoria'];
      echo'<div align = "left">';
          echo'<li>
      <a href = "index.php?idCat=' . $categoriaid . '">' . $nomecategoria . '</a>
      </li>';
  }
echo '</div>
</div id="link"><div>
</div>';
?>
    
asked by anonymous 14.03.2016 / 20:22

1 answer

0

Man, there are two different errors there.

  

SQLSTATE [HY000] [2002] Connection timed out

Tried to connect, and the connection was delayed. Probably a network problem. Draw there how "locally" does to get into the database (name, IP), and how the server does the same path. This may clear up.

  

Fatal error: Call a member function prepare () on a non-object in

Because the connection failed, all of the following fails. I tried to call the prepare() method on the $conn object, but by the way the error causes the object not to be created, so it does not have this method.

    
15.03.2016 / 04:28