Pull data from db

Asked

Viewed 607 times

1

I would like to pull the data from my db. But do not know how to connect, already have the configuration file, but do not know how to pull to use .

Connection file:

<?php
   define('BD_USER', 'root'); // USE O TEU USUÁRIO DE BANCO DE DADOS 
   define('BD_PASS', 'oi'); // USE A TUA SENHA DO BANCO DE DADOS 
   define('BD_NAME', 'painel2'); // USE O NOME DO TEU BANCO DE DADOS 
   mysql_connect('localhost', BD_USER, BD_PASS);
   mysql_select_db(BD_NAME);

HTML code:

<div class="slide">
  <div style="background-image: url('');">
    <li><a href="#">Titulo</a>
    </li>
  </div>
  • Has the image of the structure of my db: http://i.imgur.com/8aTZIi1.png

  • Enter the code of the tbm configuration file. is using mysqli or Pdo?

  • It’s a new project?

2 answers

3

It is not recommended to use the mysql_* functions that have long been out of use, it is recommended to use PDO or mysqli in new projects.

You can do as follows to list all database records, you need three steps, query definition, database execution and result extraction.

$sql = "SELECT * FROM nome_da_tabela";
$query = mysql_query($sql) or die(mysql_error());

while($row = mysql_fetch_assco($query)){
   echo $row['titulo'] .' - '. $row['link'] .'<br>';
}

Recommended reading

Why should we not use mysql type functions_*?

Mysqli vs PDO - which is the most recommended to use?

Using PDO is the safest way to connect to a PHP BD?

1

<?php
   $link = mysqli_connect("host","usúario","senha","database") or die("Error " . mysqli_error($link)); 

$sql = "SELECT * FROM nome_da_tabela";
$query = mysqli_query($link, $sql) or die(mysqli_error($link));

while($row = mysql_fetch_assco($query)){
   echo $row['titulo'] .' - '. $row['link'] .'<br>';
}
?>

Mysqli is much easier to edit, in my opinion.

Browser other questions tagged

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