MySQL query in phpMyAdmin

0

I have already researched here and in other sites but the result of my query only returns false and I do not know why.

Here is the query code

<?php

    require_once('../_php/database_class.php');

    $sql_query = "SELECT id,nome FROM 'materias_superior' WHERE id =1";

    $obj_db = new db_MySQL();
    $link = $obj_db->conecta_database();

    $resultado_query = mysqli_query($link, $sql_query);

    if($resultado_query){
        echo 'deu certo';
    } else {
        echo 'deu erro';
    }

?>

Here is the code of the connection to the bank and it does not return errors:

<?php

class db_MySQL{ 

    private $host = 'localhost';
    private $usuario = 'root';
    private $senha = '';
    private $database = 'db_mathue';

    public function conecta_database(){

        $link_conexao = mysqli_connect($this->host, $this->usuario, $this->senha, $this->database);

        mysqli_set_charset($link_conexao, 'utf-8');

        if(mysqli_connect_errno()){
            echo 'Erro ao conectar com o banco de dados: '.mysqli_connect_error();
        }

        return $link_conexao;
    }

}   

?>
    
asked by anonymous 25.12.2017 / 21:54

1 answer

1

The error is in SELECT id,nome FROM 'materias_superior' WHERE id = 1 .

When you pass the table or field names, use the grave accent "'" in this way.

SELECT id, nome FROM 'materias_superior' WHERE id = 1
    
25.12.2017 / 23:29