MYSQL extension error [duplicate]

0

I put a code page on my site that looks for information from the database but on the file that connects to the DB and pulls the relevant information giving a supposed extension error. This error does not appear in localhost only when it is hosted on an online server. The error generated is this:

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /CSS/function/conecta.coment.php on line 22

The code of the page:

<?php

//base de dados de teste

$dbhost = 'mysql.hostinger.com.br'; // endereco do servidor de banco de dados

$dbuser = 'u28*******_fraex'; // login do banco de dados

$dbname = 'u28*******_fraex'; // nome do banco de dados a ser usado

$dbpass = '**********'; // senha

$conecta = mysql_connect($dbhost, $dbuser, $dbpass, $dbname);

$seleciona = mysql_select_db($dbname);

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

$query = sprintf("SELECT user_name, comentario FROM comentario ORDER BY coment_id desc limit 5");

// executa a query

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

// transforma os dados em um array

$linha = mysql_fetch_assoc($dados);

// calcula quantos dados retornaram

$total = mysql_num_rows($dados);
?>

How can I resolve this?

    
asked by anonymous 11.10.2016 / 23:19

1 answer

0

This message is not an error but a "warning".

The mysql function will be removed from PHP very soon and the message is suggesting that you use mysqli_ or PDO .

You can learn more about mysqli in the official PHP documentation , and also you can see how to use PDO which is the most recommended.

    
11.10.2016 / 23:24