mysql deprecated [duplicate]

2

I'm trying to insert a row in mysql but it's returning this:

 Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO
    
asked by anonymous 21.07.2015 / 02:27

2 answers

5

mysql_ * functions have been deprecated since PHP 5.5. Prefer to use MySQLi or PDO (believe me, it will be much more advantageous).

"We should not use" mysql "extension functions because their development has been discontinued, the extension will become obsolete soon, meaning code that uses these functions will not work in future versions of PHP."

Why should not we use functions of type mysql_ *?

In addition, mysqli is very similar to mysql_ * so you will not have any problems learning and migrating your projects. Example:

// Conexão mysql
$db = mysql_connect('localhost', 'mysql_user', 'mysql_password');

// Conexão mysqli
$db = mysqli_connect("localhost","my_user","my_password","my_db");

MySQL functions become newer, faster and more secure, have new functions and are object oriented, that is, an evolution of the mysql _ * extension.

There is still another alternative to mysql_ * and mysqli, the PDO. It allowed you to work multiple databases and has prepared statements ( which is not so fast, but much safer).

Even the PDO being heavily criticized for bringing more problems than solutions. In my opinion, I would choose it for having support for more BD drivers and for being much more secure.

    
21.07.2015 / 02:37
3

Often, by looking for help on internet sites, they give examples as you saw, using old technologies that have already been discontinued.

The mysql_connect() , and all mysql_* functions fit into this. They are discontinued, but it does not mean that all tutorial sites have been updated.

You'll want to use, as we've explained, the new form:

$db = mysqli_connect(...); // Repara o i depois do mysql
    
21.07.2015 / 03:06