Pull data from db

1

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

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>
    
asked by anonymous 16.06.2015 / 01:19

2 answers

3

It is not recommended to use the functions mysql_ * it has already fallen into disuse for a long time it is recommended to use PDO or mysqli in new projects.

You can do the following to list all the bank records, it takes three steps, setting the query, running the database, and extracting the result.

$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 not we use functions of type mysql_ *?

MySQL vs PDO - Which is the most recommended to use?

Using PDO is the safest way to connect to a DB with PHP?

    
16.06.2015 / 01:40
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>';
}
?>

In MySQL it's much easier to edit, in my opinion.

    
16.06.2015 / 03:05