Make secure connection to the database [closed]

0

I have been told that this mode of connection is not secure, but I do not quite understand why it is not.

<?php
$conecta = mysql_connect("HOST", "LOGIN", "SENHA") or print (mysql_error()); 
print "Conexão OK!"; 
mysql_close($conecta); 
?>

And what would be the fix to make a secure connection?

    
asked by anonymous 07.11.2016 / 21:40

2 answers

1

Because the mysql_* methods were deprecated in version 5.5.0 and removed in version 7.0.0.

It is recommended to use PDO or mysqli.

Following example of use with the PDO

$pdo = PDO("mysql:host=localhost;dbname=basededados;charset=utf8", "usuario", "senha");

Another simple one using Mysqli

$mysqli = new mysqli("localhost", "user","password","database");

Which one should you choose? PDO or Mysqli? See this summary from tutsplus

Learn more about connection methods .

    
07.11.2016 / 21:52
-1

The safest way to connect is to use PDO.

Here at StackoverFLow you have a similar question and the answer is for your inquiry.

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

    
07.11.2016 / 21:48