4

Mysql extension is deprecated as of PHP 5.5.0. For sure that it will be removed in the future. However, I have thousands PHP files written many years ago in procedural instead of object oriented style. I wonder, instead of not updating the server, is there any easiest way to convert all the files with mysql extension to mysqli or pdo?

Daeus Tang
  • 41
  • 2
  • 1
    Is there any reason you need to touch that old code? If it works and you are not continuing to develop against that code base, then why mess with it? Just make sure you run those applications/services under older version of PHP. If you are continually developing against those thousands of files, then I would think the more important task is to refactor to object-oriented paradigm, part of which would be refactoring away from mysql extension. – Mike Brant Sep 17 '14 at 13:39
  • Hi Mike, it's continue developing for many years. It's almost impossible to rewrite at this stage due to limited time constraints and manpower, at least sadly not in this stage. – Daeus Tang Sep 17 '14 at 13:45
  • I still don't see a compelling reason for you to do this update. If your code base is that old both in terms of when it was written and in terms of it being primarily procedural, applying PHP version upgrades will likely expose a huge number of problems with your codebase in addition to just mysql deprecation. If you don;t have time to refactor everything for mysqli/pdo then you likely don;t have time to refactor for the other PHP upgrade issues you are going to encounter. – Mike Brant Sep 17 '14 at 13:53

2 Answers2

3

Did you say thousands of files ?

If they are working fine, I wouldn't modify the code of thousands scripts.

While it is recommended to upgrade, I suggest you to do it only when writing new code.

Every time you refactor some code, there is a risk of breaking, introducing bugs into your application.

meda
  • 45,103
  • 14
  • 92
  • 122
  • 1
    and what would happen to those thousands of files when `mysql_` is no longer supported?? ....wondering if OP should wait for it?? :\ – NoobEditor Sep 17 '14 at 13:42
  • 2
    @NoobEditor then OP should not upgrade to the major release when it is completely removed. if he wish to do so carefully port it to the new extensions. migrating thousands of file to mysqli is not an easy task. – meda Sep 17 '14 at 13:49
0

you can try with this one: https://github.com/philip/MySQLConverterTool

here you can find some other information and another useful tools: https://wikis.oracle.com/display/mysql/Converting+to+MySQLi

rvandoni
  • 3,297
  • 4
  • 32
  • 46