Mysql query in phpMyAdmin

Asked

Viewed 104 times

0

I’ve searched here and other sites but, the result of my query only returns false and do not know the pq of this.

here is the code of the consultation

<?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 connection code with the database and it returns no 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;
    }

}   

?>

1 answer

1


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

When you pass the table or field name, use the grave accent " ` ", thus.

SELECT id, nome FROM `materias_superior` WHERE id = 1
  • Actually, I could fix it. It was just removing the kkk quotes. But thanks for the help

Browser other questions tagged

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