How to Convert MySQL to MySQLi PHP Code to Upgrade to PHP7 Doing the PHP MySQL MySQLi Migration

preview_player
Показать описание


PHP 7 no longer supports the mysql extension, so any legacy code using the mysql extension will need to be migrated to either PDO or mysqli before it can run on a server running PHP 7 or above.

This article will give you examples of how to connect using mysqli and how to migrate the mysql methods to the mysqli procedural methods giving code examples for some of the simple changes to some of the more difficult ones too, even for the ones that do not have a replacement in mysqli we give you code that will help you to actually operate the mysql as if in a mysqli environment.

I also want to take a moment to talk about the mysql to mysqli package. This package was intended to be included in legacy code using the mysql extension that can be included in PHP versions 5.6 and below and it will just sit there and it waits for the mysql extension to go away.

So when the server updates to PHP 7 or above then the package will take over and it will keep the mysql legacy code from crashing your scripts.

It is intended as a stop gap is intended as to keep things running until you get an opportunity to actually get in and change and do the migration from mysql to mysqli once again it is recommended that you use this only as a stopgap that you do eventually perform the migration from mysql to either PDO or mysqli.

I hope that you find the article informative. Remember that you can also comment if you have any problems and I will get right back to you and help you work them out. Thank
you for your time. Bye.
Рекомендации по теме
Комментарии
Автор

Wow! You really did a phenomenal job on this! If it wasn't for this class, I'd be killing myself still changing scripts line by line. In fact, I used this with php.ini 'auto_prepend_file=', this way it all works completely automatically and seamlessly, no need to edit scripts at all. I even created another two scripts to register globals like the contents of all $_GET, $_POST and $_SERVER variables as they had in older versions of php, and added ereg() and eregi() which got removed from php as well. Now I don't have to edit thousands of php scripts! :)

I did notice a few small issues with your class though:

- Vulnerable to SQL INJECTION attacks due to passing $database in a SQL query: mysql_create_db and mysql_drop_db, mysql_list_tables. Presumably the original functions did not suffer from this as they probably did not pass $database in an SQL query. Not sure how to fix it, perhaps use addslashes() on it or something?

- mysql_list_processes - shouldn't that be 'show processlist'? Why is it 'mysqli_thread_id'?


Anyway, thanks again, this was amazing! :)

zaebali
Автор

thanks for the video, but how to i use this package file.

ssekyanzigeorge
Автор

hello sir i juts download the zip packaGE AND SO HOW EXACTLY DO YOU USE IT?..THE README FILE SIMPLY SAYS PUT It in your script but like where exaclty?..do i just put the 3 files in the root folder of my software script webapp?..sorry its clear at all what to do..thxz Lisa

pjmclenon
Автор

just used the package, too lazy rewrite all that code

markswanton
welcome to shbcf.ru