Difference between the mysql_connect () and mysqli_connect () functions in php


I wanted to know the difference between the two and which one is the best one to use.

$x= mysqli_connect("localhost","my_user","my_password","my_db");
$y= mysql_connect("localhost", "my_user", "my_password");

Are some of them better or newer than the others? If it is more recent what is the advantage of using the function X instead of the function Y?

asked by anonymous 11.05.2015 / 18:44

4 answers


In addition to the points mentioned in the other answers about the advantages of mysqli:

  • Object-oriented interface

  • Prepared Statements support

  • Support for multiple Statements

  • Transaction support ( Transactions )

  • Improved debugging capabilities

  • Embedded Server Support

It should also be noted that mysql_ functions no longer receive updates such as fixes and improvements and this is the vital point for you not to use mysql_ anymore, because in the near future it will no longer exist for new versions of PHP.

In other words, if you continue to mysql_ functions, two situations can happen with your projects:

  • There may be security holes in the mysql_ or bugs API.
  • When the mysql_ API is disabled, your scripts will stop working, which will cause you a lot of headaches, as you will have to redo multiple codes.
  • Note that mysqli means MySQL Improved in Portuguese, would be something like Mysql improved , referring to the API and not to the database system.

    28.05.2015 / 21:59

    This is the most recent and most recommended, mysql_connect is discontinued, with mysqli_connect being the newest and using object orientation, prepared statements, supports multiple statements, transaction support has better convenience for debug:

    11.05.2015 / 18:47

    Mysqli is newer and has support for features the other does not have, such as prepared statements, multiple statements, and transactions.

    You should use MySQLi.

    For more clarification: link

    11.05.2015 / 18:48

    The functions of the MySQLi library are newer and more complex, allowing you to execute stored procedures, functions, and other commands that were not possible with the MySQL library.

    Prefer to use the mysqli_*

    28.05.2015 / 21:08