Show database data on page

Asked

Viewed 50 times

0

I’m having trouble showing the database data on the page.

Error messages: inserir a descrição da imagem aqui

    <?php
$host = "localhost";

$db   = "faa";

$user = "root";

$pass = "";

// conecta ao banco de dados

$con = mysqli_connect($host, $user, $pass) or 
trigger_error(mysql_error(),E_USER_ERROR);

// seleciona a base de dados em que vamos trabalhar

mysql_select_db($db, $con);

// cria a instrução SQL que vai selecionar os dados

$query = sprintf("SELECT  id, nome, preco, descricao, download FROM projetos");

// executa a query

$dados = mysql_query($query, $con) or die(mysql_error());

// transforma os dados em um array

$linha = mysql_fetch_assoc($dados);

// calcula quantos dados retornaram

$total = mysql_num_rows($dados);

?>

1 answer

1

Well, according to the error returned it tells us that the function you tried to call DOES NOT EXIST or IS NOT DEFINED.

In fact from PHP 5 the calls of the Mysql functions are no longer written as "mysql...", they added a "i" to all functions calls of this genre, change the mysql_select_db for mysqli_select_db

Also, if you are not going to switch between other DB’s in your code it is more interesting to set the DB used directly at connection startup:

    $con = mysqli_connect($host, $user, $pass, $db);

Browser other questions tagged

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