The switch to MySQLi was unavoidable because the old mysql extension was quite simply outdated. Furthermore, backwards compatibility was always a priority for the extension which made it difficult to maintain the code. The code dates back to the early days of PHP and MySQL, and was not optimally developed in some respects.
For example, if the connection identifier was not explicitly defined, all functions would try to use the last one specified. Very unlucky users might even find that mysql_query() accessed a completely different database. The connection identifier was optional in the old function, but it is required in the new extension. In addition, prepared statements have been added to make retrieving data from a database table faster and more secure.
Conveniently, many functions can be modified by just adding an -i to the mysql() function. However, there are also some differences between the two extensions.
Code snippet: connection identifiers in MySQL and MySQLi
Some mysqli() functions require a connection identifier – a PHP variable created when connecting to the database. In this example, it is called $link.