0
I set up a code page on my site that looks for information from the database but in the file that connects to DB and pulls the pertinent information this giving a supposed extension error. This error does not appear on the 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 fix this?
This type of connection is no longer used and is discouraged as it is too insecure for SQL Inject, use PDO instead for being safer.
– Pedro Soares
and how I could change it to PDO?
– Fratura Exposta