select returning blank being already entered things in the database (php with msql) [closed]

-1

Anyone can help me I do not know why the result is not appearing on the page

    
asked by anonymous 10.11.2016 / 20:30

1 answer

1

You need to connect to the database and run the query.

To connect would be something like:

function conectar()
{
    try
    {
        //Localhost
        $host = "localhost";
        $user = "root";
        $password = "";
        $database = "nomedobanco";

        $conn = mysqli_connect($host, $user, $password, $database);            
    } catch (Exception $ex) {
        die("Erro de conexão: " . mysqli_connect_error());
    }

    return $conn;
}

And to execute something like:

function listar()
{
    $link = conectar();

    $query = "SELECT * FROM tablea";

    $result = mysqli_query($link, $query) or die(mysqli_error($link));

    return $result;
}
    
10.11.2016 / 20:42