My hosting does not connect the bank

Asked

Viewed 104 times

0

When upling the database appears 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 connect? because local 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>';
?>
  • Your connection is not valid, second error.

1 answer

0

Man, there are two different mistakes there.

SQLSTATE[HY000] [2002] Connection timed out

Tried to connect, and the connection took a while. It’s probably a network problem. Draw there how "locally" does to get to the database (name, IP), and how the server does the same. This can clarify.

Fatal error: Call to a Member Function prepare() on a non-object in

Since the connection failed, everything that follows fails. Tried to call the method prepare() in the object $conn, but by the way the error makes the object has not been created, so it does not have this method.

Browser other questions tagged

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