Cool MySQL to MySQLi Online Converter Tool

Created: August 1, 2017
Last Modified: December 16, 2020
Subscribe to Internet Tips and Tools Feed

Convert any php MySQL code into MySQLi code instantly. Paste your code in the box below and press "Convert". Please make sure that you have a backup of your code before you use the code provided by this converter. There are no guarantees.



Your converted mysqli code will appear in the box below:

Sea Breeze Computers Home Page

Copyright © 2017 by Jeff Baker


6/14/2020 - Version 1.2n - Bug Fix: Fixed a bug where the mysql connection link was defaulting to $mysqli instead of getting the link from a statement like $link = mysql_connect();

5/13/2020 - Version 1.2m - Converter was converting & to & in orginal source box. Hopefully that is fixed. Also, converter was having a problem with nested functions like: $sql_row = mysql_fetch_row(mysql_query($sql)); and only converting the first function to mysqli. Hopefully this has been fixed at well.

11/12/2019 - Version 1.2k - Fixed $link->close so it has parentheses with $link->close()

8/20/2019 - Version 1.2j - Added conversion for mysql_pconnect to mysqli_connect.

7/12/2019 - Version 1.2i - The converter was putting too many closing parentheses on object oriented ->data_seek(n). This has been fixed.

7/11/2019 - Version 1.2h - The converter was still getting confused with some nested parentheses. Hopefully this version has fixed the problem.

5/27/2019 - Version 1.2g - The converter is even better at capturing functions and variables with a better recursive balanced parentheses match algorithm.

5/2/2019 - Version 1.2f - Bug fix: $link = @mysql_connect() was converting to $link = @ = new mysqli() . Since @ is not recommended to suppress errors, the @ is now removed completely in front of mysql_connect when converted.

5/1/2019 - Version 1.2e - Bug fix: The object oriented conversion of mysql_result() was not putting the proper number of closing parentheses for $mysqli->query($dataquery->data_seek());

4/27/2019 - Version 1.2d - The bug fix for version 1.2c was accidentally capturing too many parentheses and getting multiple functions on one line such as: $result=mysql_query($query, $link) or die(mysql_error()). This has been fixed!

4/26/2019 - Version 1.2c - Bug fix: Previously the converter was having a difficult time with recursive parentheses in mysql statements and therefore splitting at the wrong commas. This has hopefully been fixed.

3/28/2019 - Version 1.2b - Bug Fix: Previously mysql_numrows was being incorrectly converted to mysqli_numrows. This has been fixed so that it correctly converts to mysqli_num_rows.

8/13/2018 - Version 1.2 - Bug Fix: A conversion of code like if (mysql_db_query($DBName, $Query, $Link)) was not converting to proper code. This has been fixed.

7/6/2018 - Version 1.1 - Changed conversion of MYSQL_NUM => MYSQLI_NUM to only convert if it is uppercase letters so that it will not convert mysql_num_rows to MYSQLI_NUM_rows.

08/01/2017 - Version 1.0 - Cool MySQL to MySQLi Online Converter Tool created.

Back to
Subscribe to Internet Tips and Tools Feed        

User Comments

There are 115 comments.

Displaying first 50 comments.

1. Posted By: David Hay - - July 6, 2018, 7:35 am
Hi! This mysql to mysqli converter is the best I have found around, thank you!

Just one small thing, mysqli_num_rows comes through as MYSQLINUM_rows which errors.
Thanks again for the cool tool.

2. Posted By: Jeff - - July 6, 2018, 4:28 pm
Hi David Hay,

You're welcome! Thanks for the information. I think I fixed the bug you were having. Would you like to test it again?


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
I'm sorry, I don't know what you mean. Can you give us an example of the code you are trying to convert and what you are expecting the converter to do?


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
Hi aisahmk,

That is good to know. Thank you for the update!


7. Posted By: Kasper222 - - August 14, 2018, 3:47 am
Hi Jeff, thanks for making this converter. I'm lost with all of this stuff. I have old mysql and wanted to convert to mysqli. I ran my code but got an error that I don't know how to fix.

Original code:
$Query="DROP TABLE $TableName";
if (mysql_db_query($DBName, $Query, $Link)) { do some stuff

New output code:
$Query="DROP TABLE $TableName";
if (mysqli_select_db( $Link,$DBName);=mysqli_query( $Link, $Query)) {

That semi colon is causing an error. How do I fix this?

Thanks in advance!

8. Posted By: Jeff - - August 14, 2018, 6:26 am
Hi Kasper222,

I apologize for that. mysql_db_query was deprecated a long time ago and the converter is not handling the if statement properly. Hopefully, in the future I will be able to fix the converter to work properly with the if statement. In the meantime I think you can change the code to this:

$Query="DROP TABLE $TableName";
mysqli_select_db( $Link,$DBName); $result=mysqli_query( $Link, $Query));
if ($result) {


9. Posted By: Jeff D - - October 4, 2018, 9:45 pm
I can't believe how well this thing worked! I have used other ones in the past that didn't seem to work... I pasted all my code, and boom, hours of frustration saved, it just works. You have received a tip my friend, you are amazing...

I just spinned a new droplet, and it has all the new PHP and all that... been procrastinating on switching to the new MYSQLI because in the past it still worked even though it was deprecated... now it doesn't work so you gotta switch.


10. Posted By: Jeff - - October 5, 2018, 11:25 am
Hi Jeff D,

Thank you very much for the tip and the words of gratitude.


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)

12. Posted By: Jeff - - October 30, 2018, 8:47 am
You are welcome! Thank you for the comment and letting us know the result.


13. Posted By: Naresh - - November 23, 2018, 6:30 pm
My website is - can you help me for upgrade my version 5.6 to 7.2

14. Posted By: Terry - - November 27, 2018, 11:38 pm
Thanks for making this tool public.

Have older script like to convert and has many files. Before starting, could you tell me the difference between:

Object oriented code | Procedural code

Not positive which to choose and hate to choose wrong one with all the files need to convert:)

Thank you again!

15. Posted By: Jeff - - November 28, 2018, 9:09 am
Hi Terry,

From what I have read, most programming is going in the direction of Object Oriented code. So if you start programming using Object Oriented Code then if you ever have to convert again, the code will be closer to the direction things are moving toward. So if you ever needed to update the database programming again in the future, Object Oriented programming would probably be what you would come across.


16. Posted By: Terry - - November 28, 2018, 12:48 pm
Thanks for explaining and advice Jeff.

Will take a closer look at options now that I have idea of the route to take:)

17. Posted By: Mads - - December 2, 2018, 12:59 pm
Thank you for this converter, helped me quickly find out where to touch up my code when webhost upgraded. and

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
Hi David,

You're welcome. Thank you for your suppport!


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
Hi Jeff

First of all, thanks for the great converter! I came across a piece of code that seems to have confused it, and thought I'd report it in case you'd like to fix it. Of course I can also simplify my code to the essentials, and then the converter works...

$nid=mysql_result ($_db->query("SELECT id FROM udb_tag_author ORDER BY Author ASC Limit 1"),0);

mysqli_data_seek($_db->query("SELECT id FROM udb_tag_author ORDER BY Author ASC Limit 1", ); $nid=mysqli_fetch_array($_db->query("SELECT id FROM udb_tag_author ORDER BY Author ASC Limit 1")[0],0);

mysqli_data_seek($_db->query("SELECT id FROM udb_tag_author ORDER BY Author ASC Limit 1", 0); $nid=mysqli_fetch_array($_db->query("SELECT id FROM udb_tag_author ORDER BY Author ASC Limit 1")[0],0);

22. Posted By: Jeff - - December 24, 2018, 10:04 am
Thank you for reporting it. Sorry about that. The converter can't handle the nested functions. It only works with code like this:

$result=$_db->query("SELECT id FROM udb_tag_author ORDER BY Author ASC Limit 1");
$nid=mysql_result ($result,0);

Unfortunately, I don't think I will be able to fix it. I haven't looked at the code in a long time and in order to support nested functions I would have to overhaul not just those functions but many others. It would take a lot of time and research. Thanks again for reporting it though.


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
Hi tineC,

I'm glad you found the converter helpful. Thank you for the comment!


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
Hi dave,

Thanks for notifying me. mysql_numrows is an alias for mysql_num_rows. Apparently, I overlooked it because it was rarely used by developers. I have fixed the converter so that it correctly converts mysql_numrows to mysqli_num_rows.

Unfortunately, it will take me a while before I can program the converter to have a field to specify the connection or link variable. In the meantime though there is a workaround. If you always put this line at the top of the textbox to convert:

Then the converter will realize that $link is the connection variable for the rest of the conversion. For example, if you put:

then the converter will convert it to:


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
Hi L,

Yes, that is to prevent abuse and overuse of the server. It can be very taxing on the server. It is best to only do a few lines at a time in the converter.


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
I'm sorry the converter did not work for you. Unfortunately, the converter will not work well if there is unconventional programming styles. It is better to do a few lines at a time with the converter rather than try to do a whole file. Again, my apologies. I try to fix any bugs if people report them.


33. Posted By: Jeff - - April 26, 2019, 1:55 pm
Hi Bilal,

Thank you very much for providing me with your mysql code that did not convert properly. For some reason the converter was having a hard time with the recursive parentheses in the mysql statements. I think I was able to fix it. Hopefully, the fix did not mess anything else up in the converter. Would you be able to test it?


34. Posted By: tey - - April 26, 2019, 8:28 pm
$tpelajar=mysql_query($query_tpelajar, $Myconjpn) or die(mysql_error());
convert to
$tpelajar=$Myconjpn) or die(->query($query_tpelajar)->error;


$tpelajar=$Myconjpn->query($query_tpelajar) or die($mysqli->error);

Please modified, TQVM

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
Hi tey,

I'm sorry about the bug. Thank you for notifying us about it. I think it is fixed now if you would like to test it.


37. Posted By: Rob - - April 27, 2019, 8:49 pm
I'm having difficulty converting the following code:

@mysql_select_db($db2use) or die("Unable to select database");

Which comes back as:

$mysqli=new mysqli($dbhost,$dbuser,$dbpass);
@$mysqli->select_db($db2use) or die("Unable to select database");

But when the code is loaded on the website, my error_log gets this message:

PHP Fatal error: Uncaught Error: Class 'mysqli' not found in /folder/file.php:1

(folder/file is just placeholder, the 1 corresponds to the first line of the code i've included)

Any suggestions?

38. Posted By: Jeff - - April 28, 2019, 10:00 am
Hi Rob,

It sounds like your server does not have mysqli installed. You should contact your server admin about installing it for your account.


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
Hi Ali,

Did you try googling the error? It looks like there was no mysqli_result variable given to mysqli_fetch_array(). That could also mean that the mysqli_query statement did not return a result with any rows. After running mysqli_query you may need to check for errors or see if there are any rows in the result.


41. Posted By: Ali - - May 7, 2019, 9:38 am
Thanks for your response.

42. Posted By: Andrew - - May 14, 2019, 12:38 pm
Really a great mysql -> mysqli converter.

One minor glitch:
mysql_errno() is converted to mysqli_errno()
should be to mysqli_errno($mysqli)

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
Hi Andrew,

Thanks for the information. Unfortunately, PHP did not implement mysqli_field_name. The function does not exist. For alternatives see this post:

So it will be a while before I will be able to add a difficult conversion like that.


45. Posted By: Andrew - - May 16, 2019, 12:28 pm
Hi Jeff,

Thank you for the quick response! Your converter is really excellent " saved me days of work!

Are there are other mysql_ functions where there is no mysqli_ equivalent?



46. Posted By: Jeff - - May 16, 2019, 12:42 pm
Hi Andrew,

Yes, there are quite a few mysql_ functions without mysqli_ equivalents. Unfortunately, I'm not sure if I know all of them. But here are a few that I know of.

These are functions that the mysql2mysqli converter will actually create an alternative conversion for even though there is no mysqli_ equivalent:


And these are functions that have no equivalent that I have not been able to program an alternative conversion for:



47. Posted By: nyasoso munjo - - June 7, 2019, 12:13 am
Please help,i get this error after converting from msql "
if ($counter=mysql_fetch_array(mysql_query ($Query))) "

This error apears on browser "Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR) in C:\xampp\htdocs\automate\includes\functions.php on line 472"

The code line after coverting is below
"if ($counter=$mysqli->query($Query))->fetch_array() "

48. Posted By: Jeff - - June 7, 2019, 9:32 am
Hi nyasoso munjo,

I'm sorry but the converter cannot handle nested commands like that. If you want the converter to handle it then you can change the original code to something like this:

$result=mysql_query($Query) ;
if ($counter=mysql_fetch_array($result))

Or you can change the converted code to something like this:

$result=$mysqli->query($Query) ;
if ($counter=$result->fetch_array())


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
got this error

function log($type, $message, $user=0, $action_id=0)
global $dbprefix;
$query="INSERT INTO " . $dbprefix . "logs (type, message, ip, action_id, user_id, timestamp) VALUES
('" . $type . "', '" . mysql_real_escape_string($message) . "', '" . $_SERVER['REMOTE_ADDR'] . "', " . $action_id . ", " . $user . ", " . time() . ")";
$this->check_mysql($res, $query, __LINE__, __FILE__);
function log($type, $message, $user=0, $action_id=0)
global $dbprefix;
$query="INSERT INTO " . $dbprefix . "logs (type, message, ip, action_id, user_id, timestamp) VALUES
('" . $type . "', '" . '" . $_SERVER['REMOTE_ADDR'] . "'->real_escape_string($message) . "')";
$this->check_mysql($res, $query, __LINE__, __FILE__);
error result
PHP Parse error: syntax error, unexpected 'REMOTE_ADDR' (T_STRING)