Migrate mysql to mysqli php

MySQL functionMySQLi proceduralMySQLi Object oriented styleNotesmysql_affected_rows() mysqli_affected_rows($link) $mysqli->affected_rows number of affected rows mysql_close($link) mysqli_close($link) $mysqli->close() close MySQL connection mysql_connect($host, $user, $password) $link = mysqli_connect($host, $user, $password, $database) $mysqli = new mysqli($host, $user, $password, $database) open connection to the MySQL Server mysql_data_seek($result, $i) mysqli_data_seek($result, $i) $result->data_seek($i) move internal result pointer mysql_db_name($db_list, $i) retrieve database name from call to mysql_list_dbs mysql_db_query($database, $query) select default database mysql_errno mysqli_errno($link) $mysqli->errno numeric value of error message from last MySQL operation mysql_error mysqli_error($link) $mysqli->error Returns text of the error from last MySQL operation mysql_escape_string mysqli_escape_string $mysqli->real_escape_string($value) escape string for mysql_query mysql_fetch_array($result) mysqli_fetch_array($result, $type) $result->fetch_array(MYSQLI_NUM)
$result->fetch_array(MYSQLI_ASSOC)
$result->fetch_array(MYSQLI_BOTH) fetch a result row as an associative or numeric array, or both mysql_fetch_assoc mysqli_fetch_assoc($result) $result->fetch_assoc() fetch a result row as an associative array mysql_fetch_field mysqli_fetch_field($result) $result->fetch_field() get column information from a result and return as an object mysql_fetch_lengths mysqli_fetch_lengths($result ) $result->lengths get the length of each output in a result mysql_fetch_object mysqli_fetch_object($result, $class, $params) $result->fetch_object() fetch a result row as an object mysql_fetch_field mysqli_fetch_field($result) $finfo = $result->fetch_field()
$result->fetch_field_direct($i) column information from result as object mysql_fetch_row mysqli_fetch_row($result) $result->fetch_row() get result row as enumerated array mysql_field_len length of the specified field mysql_field_name name of the specified field mysql_field_seek mysqli_field_seek($result, $number) $result->field_seek($i) set result pointer to a specified field offset mysql_field_table name of table containing the specified field mysql_free_result mysqli_free_result(result) $result->free free result memory mysql_get_client_info mysqli_get_client_info() mysqli_get_client_info() get MySQL client info (no connection required) mysql_get_host_info mysqli_get_host_info($link) $mysqli->host_info get host info mysql_get_proto_info mysqli_get_proto_info($link) $mysqli->protocol_version get protocol info mysql_get_server_info mysqli_get_server_info($link) $mysqli->server_info get server info mysql_get_server_version mysqli_get_server_version($link) $mysqli->server_version integer version of the MySQL server mysql_info mysqli_info($link) $mysqli->info get information about the most recent query mysql_insert_id mysqli_insert_id($link) $mysqli->insert_id get the ID generated from the last query mysql_list_dbs($link) $query = "SHOW DATABASES"; $mysqli->query('SHOW DATABASES') list databases available mysql_list_tables $query = "SHOW TABLES"; $mysqli->query('SHOW TABLES') List tables in a MySQL database mysql_num_fields mysqli_num_fields($result) $result->field_count number of fields in result mysql_num_rows mysqli_num_rows($result) $result->num_rows number of rows in result mysql_query($query) mysqli_query($link, $query) $mysqli->query($query) execute a MySQL query mysql_real_escape_string mysqli_real_escape_string($link) $mysqli->real_escape_string escape special characters in a string mysql_result get result data mysql_select_db($database, $link) mysqli_select_db($link, $database) $mysqli->select_db($database) select a MySQL database mysql_set_charset mysqli_set_charset($link, $charset) $mysqli->set_charset("utf8") set the client character set mysql_stat mysqli_stat($link) $mysqli->stat() get current system status mysql_tablename get table name of field mysql_thread_id mysqli_thread_id($link) $mysqli->thread_id the current thread ID

Displaying first 50 comments.

1. Posted By: David Hay - - July 6, 2018, 7:35 am


2. Posted By: Jeff - - July 6, 2018, 4:28 pm
3. Posted By: aisiahmk - - July 18, 2018, 2:48 am

convert work for login but update database not work


4. Posted By: Jeff - - July 18, 2018, 4:09 am
5. Posted By: aisiahmk - - July 19, 2018, 2:22 pm

Sorry already solve. My fault, not your converter. Your converter is the best.


6. Posted By: Jeff - - July 19, 2018, 4:46 pm
7. Posted By: Kasper222 - - August 14, 2018, 3:47 am
8. Posted By: Jeff - - August 14, 2018, 6:26 am
9. Posted By: Jeff D - - October 4, 2018, 9:45 pm
10. Posted By: Jeff - - October 5, 2018, 11:25 am
11. Posted By: Voklee - - October 29, 2018, 2:26 pm

Thanks for this great tool! I have converted a website today and it runs now fine on PHP 7.1. (was 5.4)
GREAT!


12. Posted By: Jeff - - October 30, 2018, 8:47 am
13. Posted By: Naresh - - November 23, 2018, 6:30 pm

My website is - sattamatka.store can you help me for upgrade my version 5.6 to 7.2


14. Posted By: Terry - - November 27, 2018, 11:38 pm
15. Posted By: Jeff - - November 28, 2018, 9:09 am
16. Posted By: Terry - - November 28, 2018, 12:48 pm
17. Posted By: Mads - - December 2, 2018, 12:59 pm
18. Posted By: David - - December 7, 2018, 9:24 am

Saved me several hours of work, appreciate it. Tipped you guys $10, well deserved.


19. Posted By: Jeff - - December 7, 2018, 6:40 pm
20. Posted By: kalchev - - December 21, 2018, 3:34 am

Very good tool! Just a laugh - everywhere, mysql connectin is called $ mysqli (and for instance, it's called $ conn) and must be searched and replaced manually. Just specify this explicitly, otherwise the scripts do not work.


21. Posted By: code flow - - December 24, 2018, 7:26 am
22. Posted By: Jeff - - December 24, 2018, 10:04 am
23. Posted By: tineC - - March 23, 2019, 12:13 am

This is very helpful to me. Great work! It help me in my thesis fro converting outdated sdk.


24. Posted By: Jeff - - March 23, 2019, 10:39 am
25. Posted By: dave - - March 27, 2019, 11:28 pm

Hi There, me again, almost there now, just getting mysql_numrows when it should be mysql_num_rows. Thanks again, great tool. Also, would be super handy to add a field for $mysqli connection variable name in output.


26. Posted By: dave - - March 27, 2019, 11:30 pm

I mean mysqli_num_rows()


27. Posted By: Jeff - - March 28, 2019, 11:25 am
28. Posted By: L - - April 23, 2019, 4:38 am

Can't convert code over 600 lines (even after changing max length from inspect element)


29. Posted By: Jeff - - April 23, 2019, 10:17 am
30. Posted By: L - - April 23, 2019, 10:21 am

Thanks. It works almost well, but I've noticed that my code has undefined variable names. I've converted over 50 files and many of them had $mysqli variables used but there are no $mysqli variables declared in any of files. I just replaced $mysqli variable with $link in the whole project and I hope it will be fixed now.


31. Posted By: Bilal - - April 25, 2019, 4:45 am

Very disappointed with this converter. Many of my files did not convert properly. Had to re-do the work manually all over again.


32. Posted By: Jeff - - April 25, 2019, 9:53 am
33. Posted By: Jeff - - April 26, 2019, 1:55 pm
34. Posted By: tey - - April 26, 2019, 8:28 pm
35. Posted By: Tey - - April 26, 2019, 8:30 pm

Thank you very much for your excellent work. This converter is absolutely Great. Well Done.


36. Posted By: Jeff - - April 27, 2019, 12:00 pm
37. Posted By: Rob - - April 27, 2019, 8:49 pm
38. Posted By: Jeff - - April 28, 2019, 10:00 am
39. Posted By: Ali - - May 3, 2019, 6:40 pm

Please what can i do to rectify this Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given


40. Posted By: Jeff - - May 6, 2019, 10:39 am
41. Posted By: Ali - - May 7, 2019, 9:38 am

Thanks for your response.


42. Posted By: Andrew - - May 14, 2019, 12:38 pm
43. Posted By: Andrew - - May 16, 2019, 8:54 am

Another glitch:
mysql_field_name( is not being converted to mysqli_field_name(


44. Posted By: Jeff - - May 16, 2019, 10:50 am
45. Posted By: Andrew - - May 16, 2019, 12:28 pm
46. Posted By: Jeff - - May 16, 2019, 12:42 pm
47. Posted By: nyasoso munjo - - June 7, 2019, 12:13 am
48. Posted By: Jeff - - June 7, 2019, 9:32 am
49. Posted By: Daniel Castro - - June 26, 2019, 12:58 pm

Thank you for saving me 2 minutes of my life, lol


50. Posted By: old code shark - - July 10, 2019, 9:54 am

How can I convert MySQL database to MySQLi in PHP?

To open new connection to the database with MySQLi you need to create new instance of MySQLi class. $mysqli = new \mysqli($host, $user, $password, $dbName); $mysqli->set_charset('utf8mb4');

Can I use both MySQL and MySQLi?

It is possible to include both MySQL and MySQLi when connecting to a single database, but it is incredibly delicate and with large amounts of data being passed through it can get very messy and hard to control. it is best to use MySQLi in general in my opinion because it is much more secure and up to date.

Does PHP 5.6 support Mysql_connect?

It's still available in 5.6.

Is MySQLi better than MySQL?

MySQLi supports both procedural interfaces and object oriented interfaces while MySQL supports only procedural interfaces. MySQLi supports stored procedure but MySQL does not. There is enhanced security and improved debugging features in MySQLi where this is comparatively lagging in MySQL.