These are nothing but the APIs of PHP that is used to access the MySQL databases and tables. The developers can choose either one of them for their project, however, the use of MySQL extension is deprecated and will not be available in future versions. It is recommended to use the MySQLi extension with PHP 5.5 and above.
Let’s have some more information about each of them:
MySQL: This was the main extension that was designed to help PHP applications send and receive data from the MySQL database. However, the use of MySQL has been deprecated and removed as of PHP 7 and its newer versions. This is why it is not recommended for new projects, and that’s the reason why MySQLi extensions are used more nowadays.
MySQLi: The ‘i’ in MySQLi stands for Improved. Therefore, this is also known as the improved version of MySQL. It has many useful features.
- An Object-oriented interface
- Support for prepared statements
- Support for multiple statements
- Support for transactions
- Enhanced debugging capabilities
- Embedded server support.
What I did to convert all my projects into MySQLi complaint is by replacing the following MySQL methods with the equivalent MySQLi method.
mysql_connect –> mysqli_connect
mysql_select_db –> Nil
mysql_query(” –> mysqli_query($config_con, “
mysql_query( –> mysqli_query($config_con,
mysql_fetch_array –> mysqli_fetch_array
mysql_num_rows –> mysqli_num_rows
mysql_insert_id(); –> mysqli_insert_id($config_con);
mysql_close –> mysqli_close
If you are using notepad++ or an equivalent text editor then you can use the option “Find in Files” to replace all the occurrences within the project.
There some many more methods are also needed to be replaced if you are using the same in your project. The following are popularly used methods of MySQL, followed by the equivalent methods in MySQLi.
mysql_affected_rows -> mysqli_affected_rows($link)
mysql_close -> mysqli_close($link)
mysql_data_seek -> mysqli_data_seek( $result, $offset)
mysql_errno -> mysqli_errno( $link)
mysql_error -> mysqli_error( $link)
mysql_fetch_array -> mysqli_fetch_array( $result, $type)
mysql_fetch_assoc -> mysqli_fetch_assoc( $result)
mysql_fetch_lengths -> mysqli_fetch_lengths( $result )
mysql_fetch_object -> mysqli_fetch_object( $result, $class, $params)
mysql_fetch_row -> mysqli_fetch_row( $result)
mysql_field_seek -> mysqli_field_seek( $result, $number)
mysql_free_result -> mysqli_free_result(result)
mysql_get_client_info -> mysqli_get_client_info( $link)
mysql_get_host_info -> mysqli_get_host_info( $link)
mysql_get_proto_info -> mysqli_get_proto_info( $link)
mysql_get_server_info -> mysqli_get_server_info( $link)
mysql_info -> mysqli_info( $link)
mysql_insert_id -> mysqli_insert_id( $link)
mysql_num_rows -> mysqli_num_rows( $result)
mysql_ping -> mysqli_ping( $link)
mysql_query -> mysqli_query( $link, $query)
mysql_real_escape_string -> mysqli_real_escape_string( $link)
mysql_select_db – > mysqli_select_db( $link, $database)
mysql_set_charset -> mysqli_set_charset( $link, $charset)
mysql_stat -> mysqli_stat( $link)
mysql_thread_id -> mysqli_thread_id( $link)