#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    400
    Rep Power
    34

    Transition to latest php/mysql


    I need advice. I'm not sure where to start. I need to transition a bunch of code from php 4.3.8 to whatever the latest flavor is king.

    Where would you advise I start? Why do you advise I start there?

    As always, thanks for the help. I appreciate it more than I can say.
    HeadElf
    OfficeElf.com
  2. #2
  3. Code Monkey V. 0.9
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2005
    Location
    A Land Down Under
    Posts
    2,385
    Rep Power
    2105
    The "latest flavour" is version 7. Preferably the latest version that you can have set up on your hosting server.

    As for testing, the best thing to do is set up a development area with the same specs as your production server, and try to run the code with all forms of error and notice reporting turned on. That will show you all of the errors and anything that should be fixed up.
  4. #3
  5. Impoverished Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,694
    Rep Power
    9646
    4.3? Ouch. Oldest version currently supported is 7.1.

    Check out the official migration guides. Yes, there are a lot of changes so you need to read each one: 4 -> 5.0 -> 5.1 -> 5.2 -> 5.3 -> 5.4 -> 5.5 -> 5.6 -> 7.0 -> 7.1.
    There is no PHP 6.

    The 4 -> 5 change is the biggest one in terms of PHP's behavior. 5 -> 7 was big too but mostly in terms of improvements and fixes, so most PHP 5 code runs fine on 7, however 4->5 changed a number of things and PHP 4 code won't necessarily work as well with PHP 5.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2016
    Posts
    125
    Rep Power
    65
    The appendix in the php.net documentation contain migration sections that list the major changes that have occurred in php. This would be the best place to start. You should target the latest php 7 version in order to 'future proof' your code.

    The major things that will impact older code are -

    1) Removal of register_globals. You should use the correct $_POST, $_GET, $_FILES, $_COOKIE, $_SESSION, and $_SERVER (super-global) variables where the data is defined/stored, rather than expect user variables to be 'magically' populated and overwritten from these different sources. Also, there is a $_REQUEST variable that should be avoided, as it combines $_GET, $_POST, and $_COOKIE and can therefore result in unexpected value changes if you or someone else modifying the code 'forgets' if there are same name usage between these three sources.

    2) Removal of 'registering' session variables. This is separate in operation from register_globals. To set or reference session variables, use session_start() and set or reference elements in the $_SESSION variable.

    3) Removal of magic_quotes. This provided some protection against sql special characters in external data from breaking sql query syntax, which is how sql injection is accomplished. The best method of dealing with this is to use prepared queries. Prepared queries will actually simplify code or code changes (eliminates any xxxx_escape_string() function calls there may be now or eliminates the need to add them) and simplifies the sql query syntax (eliminates any variables, quotes-around variables, and any concatenation dots and replaces each with a simple ? place-holder.)

    4) Removal of the php mysql database extension. This will require converting all database related code to use a different database extension. The php PDO extension is the best choice. It is simpler and more consistant then the mysqli extension and it has the added benefit of being usable with other database types, so once you learn the php PDO statements, you can switch to a different database type by only making sql query changes.

    5) Elimination of the POSIX Regex Functions. This will require converting code to use the PCRE Functions.

    6) Misc pass by reference, return values from functions on errors, and indirect reference parsing that will require code changes.

    7) A bunch of other changes that won't affect most code.

    One addition that will simplify database code or eliminate the amount of code you have to convert, is the addition of exceptions for database statement errors. This will eliminate most error handling logic you may have now in the code (you will still need 'local' error handling for things like duplicate key errors) and it will let you control what happens with the actual error information simply by changing php settings. If you enable exceptions for database statement errors (for the PDO extension, an exception always occurs for connection errors), and let php catch the exceptions, it will use its error_reporting, display_errors, and log_errors settings to control what happens with the actual error information. This will let you display errors when developing and debugging code/queries and log errors when on a live/public server.
    Last edited by DSmabismad; February 22nd, 2018 at 07:40 PM.
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2017
    Location
    Lithuania
    Posts
    48
    Rep Power
    46
    That might need lots of rewrite, depending on your code.

    I would probably start with setting error_reporting to ALL and running my existing code on PHP 7. This way, you will see error messages along with basic descriptions, so you will be able to modify the code accordingly. Of course, you won't be able to spot all the errors this way (unless your code is small). After that, I would probably compile a list of deprecated functions in each version of PHP 4.3.8+, and would search for each of this function in the code.
    Do you license and update your PHP scripts?
  10. #6
  11. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    400
    Rep Power
    34
    Ooo! Version guides! Thanks so much!
    HeadElf
    OfficeElf.com
  12. #7
  13. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    400
    Rep Power
    34
    Excellent advice! This I can do!
    HeadElf
    OfficeElf.com
  14. #8
  15. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    400
    Rep Power
    34
    Wonderfully comprehensive overview. Thanks. Some of those will bite me (sessions and mysql) but thanks to this I know they're coming.
    HeadElf
    OfficeElf.com
  16. #9
  17. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    400
    Rep Power
    34
    Sadly, code is *not* small so the "search for" is very good advice. Getting a testing environment up is first step. I hope to take this opportunity to consolidate different bits of code with like functions. Thanks for your help.
    HeadElf
    OfficeElf.com

IMN logo majestic logo threadwatch logo seochat tools logo