Select works on localhost but does not work on the server

2

The select was working normally in wamp, however when uploading the site to the server the information on some pages simply stopped coming.

The only part where select is working is the login area of the administrative area, I have already checked my connection file and all the information hits the server, in select it.

Follow the code for one of the pages:

include 'conexao.php';

// Selecionando informações da tabela galeriafotos
$sql = "SELECT * FROM 'galeriafotos' order by datacadastro DESC";
//Selecionando informações da tabela projetos
$sql2 = "SELECT * FROM 'projetos' order by datacadastro DESC";
$resultado = mysqli_query($conexao, $sql);

$resultado2 = mysqli_query($conexao, $sql2);

And I call them on the page through the following code:

  <?php foreach($resultado as $linha) { ?>
       <tr>
       <td>
  <?php echo $linha["titulo"]; ?>
       </td>
       <td>
  <?php echo date('d/m/Y', strtotime($linha['datacadastro'])); ?>
        </td>
         <td>
         <?php echo $linha["categoria"]; ?>
          </td>

                                    <?php } ?>
    
asked by anonymous 02.10.2015 / 19:22

3 answers

0

By demonstrating the code in the question, it was not possible to fetch() so the print_r of $ result displayed mysqli_result Object ( )

include 'conexao.php';

$sql = "SELECT * FROM 'galeriafotos' order by datacadastro DESC";
$resultado = mysqli_query($conexao, $sql);

View file

<?php foreach($resultado as $linha) { ?>

The correct one is:

$sql = "SELECT * FROM 'galeriafotos' order by datacadastro DESC";
$resultado = mysqli_query($conexao, $sql);

$itens = mysqli_fetch_all($resultado, MYSQLI_ASSOC);

Or alternatively:

$sql = "SELECT * FROM 'galeriafotos' order by datacadastro DESC";
$resultado = mysqli_query($conexao, $sql);
$lista = array();
while($row = mysqli_fetch_assoc($resultado)){
   $lista[] = $row;
}
    
08.10.2015 / 16:18
1

Try using the PDO instead of mysqli_query.

example: To make the connection.

 <?php $pdo = new PDO('mysql:host=localhost;dbname=seubancodedados', 'root', 'senha');pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);?>

Select example

<?php $consulta = $pdo->query("SELECT * FROM galeriafotos order by datacadastro DESC");?>

to display the result

<?php while ($linha = $consulta->fetch(PDO::FETCH_ASSOC)) {      echo Nome: {$linha['nome']} - Usuário: {$linha['usuario']}<br />";}?>
    
02.10.2015 / 20:02
1

You should be aware of the following:

  • Checked if user, password, server and port are correct?
  • Is the table exactly the same as the development environment?
  • Are there records in the remote bank table?
  • Does SQL work if you run it directly from the remote database?
  • The application that is in the development environment is the same as wheel in the production environment?
  • 02.10.2015 / 20:06